ArticleDirectory
- Modify permissions in digital notation
- Modify permissions in text notation
I. Linux File Permissions
Each Linux file has four types of access permissions: readable (R), writable (W), executable (x), and unauthenticated (-).
Use the LS-l command to view the permissions of a file or directory. The first field of the displayed data prevails. The first field consists of 10 characters, as shown below:
-Rwxr-XR-x
- The first parameter indicates the file type,-indicates the file, and D indicates the directory.
- 2-4 bits: indicates the permission of the file owner,U permission
- 5-7 digits: indicates the permissions of the members of the file owner group,G permission
- 8-10 bits: indicates the permissions of users outside the owner's group,O permission
- 2-10 bits: The sum of permissions is sometimes called a permission.
In the preceding example, this is a file (not a directory). The file owner has the permission to read, write, and execute the file, members of the owner's group and users outside the group have read and execution permissions but no write permission.
Ii. File Permission modification ---- chmod
- Modify permissions in digital notation
The so-called numeric representation represents R, W, and X with 4, 2, and 1 respectively. If no permission is granted, it is 0. Then, the permissions are added as follows:
| Original permission |
Convert to numeric |
Numeric notation |
| Rwxrwxr-x |
(421) (421) (401) |
775 |
| Rwxr-XR-x |
(421) (401) (401) |
755 |
Example of modifying permissions: Modify the file test permission to the read and write permissions of the owner and members of the group.Only read permission
Chmod 664Test
- Modify permissions in text notation
In text notation, four letters are used to indicate different users:
-
- U: Owner
- G: group members
- O: other members
- A: All
Permissions are still represented by R, W, and X.
Unlike numeric notation, text notation not only allows you to specify permissions again, but also allows you to add or remove permissions based on the original permissions, as shown below:
-
- =: Reset Permissions
- -: Permission reduction for current settings
- +: Add permissions to the current settings.
Example: in the preceding example, the owner adds the execution permission, and the members of the group reduce the execution permission. If other Members are set to the execution permission, run the following command: chmod U + X, G-X, O = x Test
Note: there cannot be spaces before and after the comma
Iii. Directory Permissions
The modification of directory permissions is different from the modification of file permissions, but the meaning of the four permissions is as follows:
- R: List contents in a directory.
- W: You can create, delete, and modify files in a directory.
- X: You can use the CD command to switch to this directory.
- -: You are not authorized to access this directory.
Note: The Directory can use the wildcard "*" to indicate all files in the directory. For example, you can set the permission for all files in the/test directory to be read and written by anyone.
Chmod 666/Test/*
4. Specify the default file permission mask ----- umask
The permission mask consists of four Octal numbers. After the existing permissions are removed, the default permissions for this file are generated.
Generally, the default value of the new file is 0666, and the default value of the new directory is 0777. If the full-line mask is set to 0002, the default permission for each new file is 0666-0002 = 0664, the default permission for the directory is 775. You can directly enter the umask command to check the current default permission mask, or enter "umask permission mask" to specify the default permission mask.
Use umask to specify the default permission mask to avoid adding files or directories with excessive access permissions.