0. Why is permissions in Linux important?
Permissions directly related to data security!
First, the user basic concept:
- Owner: The user who owns the file. You typically have all the permissions for a directory or file.
- User group: Several users make up a group of users, generally having certain permissions at the same time in the group.
- Other person (others): relative to owner and group. Generally, some permissions are less than the previous two.
Ii. the meaning of the contents and the permissions of the file:
- The file is actually contains the data, the general text file, the database file, the binary executable file and so on, therefore the permission for the file, the meaning is as follows:
- R (Read): Can read the actual contents of this file, such as reading the text file Hello.txt in the hello,world!
- W (write): Can edit, add or modify the contents of a file (note: does not include the right to delete the file itself )
- X (EXecute): The file has permission to be executed by the system (note:under Linux, the file can be executed, not as seen under Windows file extension, but by whether the file has the X permission to determine )
- The main content of the catalog is the list of record file names. Permissions for the directory, the meaning is as follows:
- R (Read contents in directory): Represents a permission to read a list of directory structures, and when you have R permission for a directory, you can use LS to print it out
- W (Modify contents of directory): This writable permission is very powerful for the directory, and it represents that you can:
- Create a new file and directory
- Delete files and directories that already exist (regardless of permissions on the file)
- Rename a file or directory that already exists
- Transfer files and directory locations within this directory.
- In summary, the W permission of the directory is directly related to the change of file name under this directory.
- X (Access directory): Directory x on behalf of the user can enter the directory into a working directory, such as I have/data x permission, then I can cd/data, and vice versa.
For example, to view the details of the Test.txt file under/data, you can see:
[Email protected]/]# ls-l/data/test.txt-rw-r--r--. 1 Oldboy users 296 Apr 11:15/data/test.txt
In the printed result:
- First character [-]: Indicates this file is a normal file
-
- If [d] is the directory
- If [-] is the file
- If [l] is the connection file (Linkfile)
- If [b] indicates an interface device that is available for storage in the device file
- If [C] indicates a serial port device in the device file, such as a keyboard, mouse (one-time read device)
2, the following [rw-r--r--] character: Represents the permission information for this file, three a group.
- The first set of [rw-]: Indicates that the owner's permissions are R, W, readable and writable.
- The second set of [r--]: Indicates that the permissions of the same user group are R and can only be read.
- The third group [r--]: Indicates that other non-user-group permissions are R and can only be read.
Third, the Linux storage user identity and user group records files.
/etc/passwd #默认情况下, all accounts on the system are recorded in this file with general identity user and root information /etc/shadow #记录个人的密码/etc/ Group #记录所有的用户组名称 # These three files are the focus of your Linux account, password, and user group information. Do not delete it arbitrarily.
Four, change the file user group, owner, permissions of the command. (Note: The following actions are performed under root)
- Changing the file user group Chgrp (change group)
CHGRP users /root/install.log #要改变的组名必须在/etc/groupexists #将install. log file user groups instead of use RS
- Changing the file owner Chown (change owner)
Chown xiaoming/data/test.txt #目标用户必须在/etc/passwd exists #将test the owner of the. txt file is xiaoming
- Change file Permissions Chmon
- Method One, each of the permissions in Linux corresponds to a score, the corresponding table is as follows
R (Read) = = 4 W (write) = = 2 x (executable) = = 1
Changing the permissions of a file adds the required permission scores to the corresponding owner, group, and others locations. As follows
chmod 640 /data/test.txt #将/test.txt permissions change to-rw-r-----
The corresponding rw-;4 corresponding to the corresponding r--;0 of the #6 ==4+2 ---。 Only the owner can read and write, the group is readable, others does not have any permissions)
2. Method Two, previously said that the user (that is, owner), group, others three identities, in Linux with U,g,o to represent the rights of the three kinds of identities. As follows:
U + (Join a permission) R G -(remove a permission) w o = (set a permission) x A (all)
Practice: For example, to set a file's permissions as-rwxr-xr-x, which means that user has read, writable, and executable permissions, group and others (G/O) have readable and executable permissions. The code is as follows:
[Email protected]/]# chmod u=rwx,go=rx/data//]# ls-l/data/test.txt #查看权限 1296:/data/test.txt
Reference: 1, bird Brother's Linux private dishes
2, https://linux.cn/
Permissions for Linux directories and files