In-depth analysis of Linux directory permissions

Source: Internet
Author: User
Tags chmod file permissions

The following is a summary of the Linux directory permissions.

R Permission:

Permissions for the column directory. You can list the directory names, but you cannot get the attributes (dates, owner groups, permissions, and so on) in the directory, and get the attributes that require the directory to have X permissions.

W Permission:

In the directory has created, renamed, delete permissions, also affect the directory structure operations. A directory, W permission must have x permission to be valid, and the W permission alone has no effect.

X Permission:

1, access to the directory.

2, the directory of the file rwx permissions restricted by the directory x permissions, the directory has x permissions, the file under the RWX permission is valid, the directory does not have X permissions, even if the following file has rwx (any) permissions also have no effect.

Linux files have four kinds of access rights: readable (R), writable (W), executable (x), and no permissions (-).

Enter the LS-L command in the terminal to view the permissions of a file or directory under the current directory, and the first field for each row of data is the content of its permission. The first field consists of 10 characters, such as:
-rwxr-xr-x
The first digit represents the file type,-represents a file, D represents a directory, and each of the following three-bit characters represents the permissions of three different user groups.
2-4-bit permissions that represent the owner of the file, that is, U (USESR) permissions
5-7-bit permissions that represent the group members to which the file owner belongs, G (Group)
8-10-bit indicates the permissions of a user other than the group to which the owner belongs, O (others) permission
A 2-10-bit permission sum is sometimes called a (all) permission
The above field indicates that this is a file (not a directory), and that the file owner has read, write, and execute permissions.
A user who is a member of the group owned by the owner and who owns the group has read and Execute permissions without write permissions.
R, W, and X can also be represented by 4, 2, and then 0 without permission, which is more convenient when modifying permissions.
Linux to modify file permissions with the chmod command.
There are two uses of the chmod command. One is an expression that contains letters and operators, that is, a text-setting method, and the other is a numeric setting that contains numbers.
1. Text Setting method

chmod [who] [+ | - | =] [mode] File name
The Who can be any of the above mentioned U, G, O, a or their combination. The operator + 、-、 = Adds a permission, cancels a permission, gives a given permission, and cancels all other permissions (if any).
Mood is any combination of R, W, and X.
For example:
chmod g+r,o+r FileName
Represents the ability to add read permissions to file filename to the same group and other users.
2. The principle of digital setting is relatively simple
chmod [mode] filename
Regardless of what permissions to add, but can directly set what permissions, where the mood is a three-digit, each digit can be 1 to 7 of any one, representing the corresponding user type of permissions, such as:
chmod 777 FileName
This means that all users have all the permissions of filename, which is very dangerous. Modify permissions in Linux to use Administrator privileges, such as sudo or switch to the root account in Ubuntu.
Chmod can also be followed by parameters, mainly---R (to modify the directory to use)-V (Display operation).
Such as:
Chmod-r 755 dirname
To modify the permissions of all files and directories under DirName to 755, is a recursive operation of the directory.

To modify the permissions for all files in a directory at once, including file permissions in subdirectories, use the parameter-R representation to initiate recursive processing.

For example:

[Root@localhost ~]# chmod 777/home/user Note: Only the permissions for the/home/user directory are set to RWXRWXRWX

[Root@localhost ~]# chmod-r 777/home/user Note: Sets the permissions for the entire/home/user directory and the files and subdirectories therein to rwxrwxrwx

To modify the permissions for all files in a directory at once, including file permissions in subdirectories, use the parameter-R representation to initiate recursive processing.

For example:

[Root@localhost ~]# chmod 777/home/user Note: Only the permissions for the/home/user directory are set to RWXRWXRWX

[Root@localhost ~]# chmod-r 777/home/user Note: Sets the permissions for the entire/home/user directory and the files and subdirectories therein to rwxrwxrwx

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.