Explanation of the use of chmod

Source: Internet
Author: User

1. View the commands for which group the user belongs to
ID User (show user group and ID details)
Groups user (only displays the name of the group to which the users belong)

2, first explain the ls-l path (Ls-l is ll) display of the specific parameters, in the form of similar-rwxr-xr-x
9 8 7 6 5 4 3 2 1 0
-R W x r-x r-x

The 9th bit represents the file type, which can be P, D, L, S, C, B, and-:
D Represents a catalog file
L represents a symbolic connection file
-Denotes normal file
P indicates named pipe file
s represents the socket file
C represents a character device file
b represents a block device file
第8-6位, 5-3-bit, 2-0-bit represent the permissions of the file owner (that is, user), the permissions of the same group of users (that is, groups), and other users ' permissions (other), in the form of rwx:
R is readable and can read the contents of a file
W indicates writable, can modify the contents of the file
x indicates executable and can run this program
Where no permissions are used-Indicates
s denotes setuid or setgid, usually appearing together with X, when appearing separately, is uppercase S
t denotes sticky bits, which appear together with X, and are uppercase t when they appear alone.

SUID is the set User ID, SGID is the set Group ID meaning


3, the explanation of T,t,s,s
T is built on the basis of X, if T is set separately, then ll shows a large t, and if you set both X and T, only small t is displayed. T seems to be valid only for other, not for user and group.

S is also built on the basis of X, when set separately, displays large s, while setting, displays small S. s appears to be valid only for user and group, and no effect for other.


4. chmod [OPTION] ... Mode[,mode] ... FILE ...
chmod [OPTION] ... Octal-mode FILE ...
chmod [OPTION] ...--reference=rfile FILE ...
chmod parameters, referring to the man page can be understood, the main introduction of the format of the next mode.

This feature can only be used by a file owner or a privileged user to change the file access mode. Mode can be in octal digits or in the form of a who+opcode+permission character. Who is optional, default is a (all users), can only select one opcode (opcode), can specify multiple mode, separated by commas.

Who,u: User, G: Group, O: Other, A: all Users (default)
opcode,+: Add permissions,-: Delete permissions, =: Reassign Permissions
Permission,r: Read, W: Write, X: Execute, S: Set the ID number of the user (or group), T: Set the sticky bit (sticky bit) to prevent the file or directory from being deleted by the non-owner.

Mode can also represent the permissions in octal digits, the first specifies the owner's permission, the second specifies the group permissions, the third specifies the permissions of the other user, and each bit determines the permissions by 4 (read), 2 (write), 1 (executed), and three numeric values. If 6 (4+2) represents a read-write right, 7 (4+2+1) has read, write, and execute permissions.
You can also set the fourth bit, which is in front of the three-bit permission sequence, and the fourth digit value is 4,2,1, which means the following:
4, the user ID is set at execution time, which is used to authorize the file owner-based process, not to the user who created the process, that is, suid.
2, when executed, sets the user group ID, which is used to authorize the process based on the group of files, not the user who created the process, that is, Sgid.
1, set the sticky bit.

A simple example:
$ chmod u+x file adds execute permission to the owner of file
$ chmod 751 file assigns read, write, execute (7) permissions to the owner of file, assigns read, execute (5) permissions to the group where the file resides, and assigns permissions to other users to execute (1)
$ chmod Another form of the previous example (751) of u=rwx,g=rx,o=x file
$ chmod =r file to assign Read permissions to all users
$ chmod 444 File above example (=R)
$ chmod a-wx,a+r File above example (=R)
$ chmod-r u+r Directory recursively reads permissions for the owner of all files and subdirectories in directory directory
$ chmod 4755 Sets the suid to assign read, write, and execute permissions to the owner, assigning read and Execute permissions to the group and other users.

5, the explanation of the X-permission, mainly is the directory has the X-permission explanation
The executable permission (x) of a file is simple enough to be able to execute its meaning. But what does the permission to execute the directory mean? Of course, it is impossible to execute this directory, in fact, this execution permission if used in the directory, it no longer represents the meaning of execution, but instead of the "search" permission (or to understand whether the CD command can be accepted, the user can enter the directory into the working directory, note that it is not LS). When you want to access the/etc/httpd.conf file, you must have the X (that is, search) permissions on the directory/etc, or even if you have read access to the directory/etc and file httpd.conf, you cannot access the httpd.conf file.

6, the interpretation of R and W permissions, mainly for the directory with R and W interpretation
Files with R and W are read and write permissions, and the directory has r to indicate that you can get information about the list of files and subdirectories in the directory, that is, the directory structure, the directory has a W means that you can modify the structure of the directory, that is, you can delete files or delete subdirectories (this is important for deleting files).

7, SetUid, SetGid, ie: set-user ID bit, set-group ID bit
When a program (that is, a file) is set up, the process that runs the program will have the same permissions as the program owner, such as if you have a program that is rooted and setUid, even if an ordinary user runs the program, the program's identity is the same as the superuser. Access to all resources that can be accessed only by the root user. A typical example is the passwd program. Similarly, if you are setting up Setgid, you will have permissions that are owned by the group that the file belongs to, that is, the program runs by the permissions of the group.
The setuid and setgid bits are programs or commands that allow a normal user to run only the root account in the root user's role. For example, we use the normal user to run the passwd command to change their password, in fact, the final change is the/etc/passwd file, we know/etc/passwd file is a user-managed profile, only the root user can change.

8, sticky position (adhesion) Interpretation
In the previous old system, if a program file is set to the sticky bit, then when the program is aborted, all of his instruction segments will be saved to the system's swap partition, and can be transferred to the system faster when running again. However, the current operating system is no longer using this feature. But this does not mean that the function has been completely discarded. When a directory is set to sticky bit, it will play a special role, that is, when a directory is set to "sticky bit" (with chmod a+t), then the files in this directory can only be by the
Super Admin Delete
The owner of the directory is deleted
The owner of the file is deleted
This means that even if the directory is writable by anyone, only the owner of the file can delete the file.

9. When the file list information is displayed with the ls-l command, the filename is colored and the specific meanings of each color are as follows:
Blue indicates the directory, green means executable file, red indicates compressed file, light blue indicates linked file, white denotes other file; Yellow is device file, including block, Char, FIFO.

The main introduction of the 2nd
Http://zhidao.baidu.com/link?url=LpE5M8_jdWMqeYajDS7W4cY-5N8-ZYxxMdBxDUNtFvmk3-EVUvZez1kWxfiLT__DF9th67AwRM-40K_LVIWfNa
Main introduction 4th
Http://www.cnblogs.com/younes/archive/2009/11/20/1607174.html
Main introduction 5th, 6 points
Http://www.360doc.com/content/12/1014/21/9615799_241487997.shtml
Main introduction 7th
Http://www.php100.com/html/webkaifa/Linux/2010/0812/6392.html
Main introduction 8th
http://lishaohui.qd.blog.163.com/blog/static/4865891620112119298796/
Http://os.51cto.com/art/201004/194994.htm
Main introduction 9th
Http://blog.163.com/fan_yishan/blog/static/47692213200951304813300/


Explanation of the use of chmod

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.