Copyright Notice:
###########################################################################
All the contents of this article are from the author Liu Chunque's study summary, without my permission, prohibit the private forwarding and use.
qq:1151887353
E-mail:[email protected] [email protected]
##########################################################################
1th. Umask values and permissions for files and directories
1.1-r parameter Setting directory permissions (chmod)
1.2 Permission Letter Description
1.3 Umask Description
1, the value of Umask determines the permissions of the file and directory, create a file default maximum permission is 666 (-rw-rw-rw-), the default file created does not have the ability to execute the X-bit.
2, for the file, Umask is set in the assumption that the file has the octal 666 of the permission to do, the file's permission is 666 minus umask (umask each bit number can not be greater than 6, for example, 077 does not meet the criteria) of the mask value; Focus on the next content, If some or all of the bits in the umask are odd, then 1 of the result of the file permission bits corresponding to the odd number is the final file permission value.
Create directory default maximum permissions 777 (-RWX-RWX-RWX), the default directory created by the owner is the X permission, allowing the user to enter.
For the directory, Umask is set to assume that the file has octal 777 permissions, the directory octal permission 777 minus umask the number of masks;
3, the smaller the umask, the greater the permissions of the file and directory, the default Umask value is 022, that is, when both the primary and the group are root, the permissions of the file and directory are 644 (-rw-r--r--) and 755 (drwxr-xr-x);
4, first set the value of umask, such as Umask 222 and then mkdir D222,touch f222, and then ll=ls-l, so that the Umask value will take effect;
5. Control script for Umask value
6, Umask blog site
http://oldboy.blog.51cto.com/2561410/1060032
1.4 Three ways to read file and directory permissions with umask values 1.4.1 Plus subtraction (easy to use, recommended)
General calculation methods for file permissions:
Default File Permissions calculation method
1) Assume that the Umask value is: 022 (all bits are even)
6 6 6 Start Permission value for ==> file
0 2 2-value of ==>umask
---------
6 4 4
2) Assume that the Umask value is: 045 (other user group bits are odd)
6 6 6 Start Permission value for ==> file
0 4 5-Value of ==>umask
---------
6 2 1 ==> the calculated permissions. Since the last digit of umask is 5, add 1 to the other user group.
0 0 1 +
---------
622 ==> True File permissions
Default directory Permissions calculation method
7 The starting permission value for the ==> directory
0-Value of ==>umask
---------
7 55
Instance 1-1: Umask All bits are all even
[Email protected] oldboy]# umask
0022 #→umask Current Value
[[email protected] oldboy]# umask 044 #→ changed to 044
[Email protected] oldboy]# umask
0044
[[email protected] oldboy]# mkdir umask_test #→ Build Catalog Test
[Email protected] oldboy]# ls-ld umask_test
DRWX-WX-WX 2 root root 4096 19:21 umask_test#→ The corresponding digital permission is 733, is it consistent with the above calculation method?
[email protected] oldboy]# Touch umask_test.txt
[Email protected] oldboy]# ls-l umask_test.txt
-rw--w--w-1 root root 0 Nov 19:21umask_test.txt #→ corresponds to a digital permission of 622, is not consistent with the above calculation method
Instance 1-2 some or all bits of the umask value are odd
[Email protected] oldboy]# umask 0023
[Email protected] oldboy]# mkdir dir
[[email protected] oldboy]# Touch file
[Email protected] oldboy]# ls-l
Total 4
drwxr-xr--2 root root 4096 11-15 01:04 dir #→ corresponding digital permissions are 754
-rw-r--r--1 root root 0 11-15 01:04 file #→ corresponding digital permission is 644
Tip: According to the previous calculation method, when Umask is 0023, dir should have a permission of 754, and file should be 643, but because the other group bits of umask are odd, the final permission is the other group bit plus 1, that is 643 plus 001 (corresponding to the practice result 644). Note: Do not add 1 for even digits of umask
Instance 1-3 all bits of umask value are odd
[Email protected] oldboy]# umask 0551
[Email protected] oldboy]# umask
0551
Umask 0551 is calculated according to the mask method: The directory permission is 226, the file permission 115, and the actual file permission is 226 (umask three permission bits are odd, so each bit 1 is the correct permission)
[Email protected] oldboy]# mkdir DIR5
[email protected] oldboy]# Touch file5
[Email protected] oldboy]# ls-l
Total 4
D-w--w-rw-2 root root 4096 11-15 01:27 dir5 #→ directory corresponds to a digital permission of 226
--w--w-rw-1 root root 0 11-15 01:27 file5 #→ directory corresponds to a digital permission of 226
One more example of verification:
[Email protected] oldboy]# Umask 0333
[Email protected] oldboy]# umask
0333
Umask 0333 is calculated according to the mask method: The directory permission is 444, the file permission 333, and the actual file permission is 444 (umask three bits are odd, so each bit 1 is the correct permission)
[Email protected] oldboy]# mkdir dir3
[email protected] oldboy]# Touch file3
[Email protected] oldboy]# Ls-l|grep 3
dr--r--r--2 root root 4096 11-15 01:30 dir3 #→ directory corresponds to a digital permission of 444
-r--r--r--1 root root 0 11-15 01:30 file3 #→ directory corresponding digital permission is 444
1.4.2 is calculated by means of 8-letter notation
[[Email protected]oldboy]# umask 551
The Umask value is 551, and the corresponding permission is-r-xr-x--x, which means that all files and directories are removed-r-xr-x--x permissions in the permission.
File permissions: "-rw-rw-rw-"-"-r-xr-x--x" = "--w--w--rw-" =226 (no X on file X-bit, no cancellation)
Directory permissions: "-RWXRWXRWX"-"-r-xr-x--x" = "--w--w--rw-" =226 (the X-bit of the directory has x, can be canceled directly)
Continue with the previous example to verify:
[[Email protected]oldboy]# umask 333
The Umask value is 333, and the corresponding permission is-WX-WX-WX, which means that all files and directories are removed-WX-WX-WX permissions in the permission.
File permissions: "-rw-rw-rw-"-"-wx-wx-wx" = "-r--r--r--" =444 (no X on file X-bit, no cancellation)
Directory permissions: "-RWXRWXRWX"-"-wx-wx-wx" = "-r--r--r--" =444 (the X-bit of the directory has x, can be canceled directly)
1.4.3 by binary method (binary conversion software)
0022
0 2 2
----------#→ octal Conversion binary
0 10 10
Description: Converts the Umask value eight binary into binary
6 6 6
------------#→ octal Conversion binary
110 110 110
Description: Converts the file default maximum permission value eight to binary
0 10 10 #→umask Binary
-------------#→ and arithmetic
110 110 110 #→ file maximum permissions binary
-------------
000 010 010
-------------#→ convert octal
0 2 2
Note: The last obtained value is 022, then 666 minus 022, then the file creation permission is 644
[[Email protected]oldboy]# umask 551
[[Email protected]oldboy]# umask
0551
5 5 1
-------------#→ Conversion Binary
101 101 001 #→umask Binary
-------------#→ and arithmetic
110 110 110 #→ file maximum permissions binary
-------------
100 100 000
-------------#→ convert octal
4 4 0
Note: The last value obtained is 440, then 666 minus 440, then the file creation permission is 226.
1.5 Description of permissions between Enterprise Servers
The relationship between Umask value and file and directory permissions in Linux