Linux file permissions

Source: Internet
Author: User

One, Linux file permissions

Each Linux file has four access rights: Readable (R), writable (W), executable (x), and no permissions (-).
Use the Ls-l command to see the permissions for a file or directory to display the first field of data
Quasi -. The first field consists of 10 characters, as follows:
-rwxr-xr-x
The first bit represents the file type,-represents the file, and D indicates the directory
2-4-bit represents the permissions of the file owner, u permissions
5-7-bit represents the permissions of the group member to which the file owner belongs, g permission
8-10 bits represents the permissions of a user other than the group to which the owner belongs, o permissions
The sum of 2-10-bit permissions is sometimes referred to as a permission

In the above example, this is a file (not a directory), and the file owner has read, write, and execute permissions.
The owner-owned group member and a user other than the owning group have read and Execute permissions without write permission.

Second, the file permission modification----chmod
1. Modifying permissions with digital notation
The so-called digital notation, refers to the R, W and X respectively, 4, 2, one represents, does not grant permission is 0,
Then add the permissions, as follows

Original permissions Convert to Digital Numerical notation
Rwxrwxr-x (421) (421) (401) 775
Rwxr-xr-x (421) (401) (401) 755


Example of modifying permissions: Modify the permissions of the file test to have read and write permissions for the owner and group members, and other
People only have Read permission
chmod 664 Test

2. Modifying permissions with text notation
Text notation uses 4 letters to denote different users:
U: Owner
G: Group members
O: Other Members
A: Everyone
Permissions are still represented by R, W, and X

Unlike digital notation, text notation can not only reassign permissions, but also on the basis of original permissions
Increase or decrease the permissions as follows:
=: Re-establish permissions
-: Reduce permissions on current settings
+: Add permissions to current settings

Example: In the example above, the owner plus execute permissions, group members reduce execution permissions, other members are set to
Execute permissions, execute the following command
chmod u+x,g-x,o=x Test


    C, directory permissions
    Changes in directory permissions and file permissions are different, except that four kinds of permissions represent the following:
    r: Can list content in a directory
    w: Create, delete, and modify files in the directory
    x: You can use the CD command to switch to this directory
   -: No access to this directory

    Note: A directory can use wildcards "* "To represent all files in the directory, such as the
    permission set for all files in the/test directory to anyone can read and write
        chmod 666/test/*

    Four, the default permission mask for the specified file-----umask
    Permission mask has 4 octal digits, After you have removed the permission mask from the existing permissions, you can generate the default permissions for this file when you set up
   .
    in general, the default value for a new file is 0666, and the default value for the new directory is 0777, if you set the line mask setting
    to 0002, The default permission for each new file is 0666-0002=0664, and the default permission for the directory is 775.
    can enter the umask command directly to check the current default permission mask, or enter the "Umask permission Mask" To specify the implicit
    permission mask.
    Specify a default permission mask in umask to avoid adding files or directories that have too large access rights.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.