The relationship between Umask value and file and directory permissions in Linux

Source: Internet
Author: User

umask values and permissions for files and directories
1.1-r parameter Setting directory permissions (chmod)

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/92/E8/wKioL1kE0rqgJo_gAAJVm7FRtqw248.png "title=" QQ picture 20170429225829.png "alt=" Wkiol1ke0rqgjo_gaajvm7frtqw248.png "/>

1.2 Permission Letter Description

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/92/EA/wKiom1kE0ubhMvOXAAA4oD-uHX0441.png "title=" QQ picture 20170429230204.png "alt=" Wkiom1ke0ubhmvoxaaa4od-uhx0441.png "/>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/92/EA/wKiom1kE0ozDVdzKAAAf6-G85Dg968.png "title=" QQ picture 20170429230223.png "alt=" Wkiom1ke0ozdvdzkaaaf6-g85dg968.png "/>

1.3umask Description

1, The value of Umask determines the permissions of the file and directory, the default maximum permission to create the file is 666(-rw-rw-rw-) , the file created by default does not have the x -bit executable permission.

2 umask 666 666 minus Umask ( Umask The individual digits cannot be greater than 6 077 "the value of the mask; focus on the following, if umask Some or all of the bits are odd plus 1 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 eight binary 777 permissions, the directory octal permission 777 minus the umask mask number;

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 thegroup are root, the permissions of the file and directory are 644( -rw-r--r--) and 755(drwxr-xr-x);

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/92/E8/wKioL1kE0w7gIRkzAAIPq3uQWmQ930.png "title=" QQ picture 20170429225853.png "alt=" Wkiol1ke0w7girkzaaipq3uqwmq930.png "/>

4, first set The value of umask, such as umask 222 and then mkdir d222, Touch f222 , and then ll=ls-l , so umask value will not take effect;

5 . Control script for Umask value

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/92/EA/wKiom1kE0yzgjEx3AADlVDXQ9kA938.png "title=" QQ picture 20170429225907.png "alt=" Wkiom1ke0yzgjex3aadlvdxq9ka938.png "/>

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 calculation (easy to use, recommended )

General calculation method of file permissions: Default file permissions calculation Method 1) Assume that the Umask value is: 022 (all bits are even) 6 ==> file start permission value 0 2 2-==>umask value---------6 4 42) Assume that the Umask value is: 045 (its His user group is odd) 6 ==> file start Permission value 0 4 5-==>umask value---------6 ==> the calculated permissions. Since the last digit of umask is 5, add 1 to the other user group. 0 0 1 +---------622 ==> Real file permissions default directory Permissions calculation method 7 ==> directory Start permission value 0-==>umask value---------7 55

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/92/E8/wKioL1kE09iBL1hFAAQG2NBnh0I479.png "title=" QQ picture 20170429225927.png "alt=" Wkiol1ke09ibl1hfaaqg2nbnh0i479.png "/>

Instance 1-1:umask All bits are all even

[[email protected] oldboy]# umask0022 #→umask current value [[email protected] oldboy]# umask 044 #→ change to 044[[email protected] Oldboy] # Umask0044[[email protected] oldboy]# mkdir umask_test #→ Build catalog test [[email protected] oldboy]# Ls-ld UMASK_TESTDRWX-WX-WX 2 R Oot root 4096 19:21 umask_test#→ The corresponding digital permission is 733, is not 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 N OV 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 p Rotected] oldboy]# ls-l total 4drwxr-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: The file #→ corresponds to a digital permission of 644 hint: according to the previous calculation method, when Umask is 0023, dir's permission should be 754, and file permissions should be 643, but because umask other group bit is odd, so the final permission for the other group bit plus 1, i.e. 643 Plus 001 (corresponding to practice result 644). Note: Do not add 1 for even digits of umask

Example 1-3 umask when all bits of a value are odd

[[email protected] oldboy]# umask 0551[[email protected] oldboy]#  umask0551umask  for 0551  based on 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 plus 1 is the correct permission) [email  protected] oldboy]# mkdir dir5[[email protected] oldboy]# touch file5 [[Email protected] oldboy]# ls -l Total  4d-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   The   0 11-15 01:27 file5 #→ directory corresponds to a digital permission of 226 again to verify under one example: [[Email protected] oldboy] # umask 0333[[email protected] oldboy]# umask0333umask  to 0333  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 plus 1 is the correct permission) [[email protected] oldboy]#  mkdir dir3[[email protected] oldboy]# touch file3[[email protected]  Oldboy]# ls -l|grep 3dr--r--r-- 2 root root 4096 11-15 01:30 dir3  #→ directory corresponds to a digital permission of 444-r--r--r-- The  1 root root    0 11-15 01:30 file3 #→ directory corresponds to a digital permission of 444

1.4.2 through 8 binary alphabet notation calculation

[[Email protected]]# umask 551umask value is 551, the corresponding permission is-r-xr-x--x, that is, all files and directories are de--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 need to cancel) directory permissions: "-RWXRWXRWX"-"-r-xr-x--x" = "--w--w--rw-" =226 (The X-bit of the directory has X, directly cancel can) continue to take the previous example to verify: [[email protected]]# umask 333umask value is 333, the corresponding permission is-WX-WX-WX, That is, all files and directories are-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, do not cancel) directory permissions: "-RWXRWXRWX"-"-wx-wx-wx" = "-r--r--r--" = 444 (x on the directory, can be canceled directly)



1.4.3 computed by binary method (binary conversion software)

00220    2   2      ----------     #→ octal Conversion Binary 0    10   10 Description: Convert umask value eight into binary  6     6    6------------  #→ octal conversion binary 110 110   110 Description: Convert the file default maximum permission value eight into binary   0  10  10      # →umask binary-------------      #→ and Operation 110 110  110       #→ file maximum permissions binary-------------000 010  010-------------       #→ convert octal   0  2   2 Description: The last obtained value is 022, then 666 minus 022, then the file creation permission is 644[[ Email protected]]# umask 551[[email protected]]# umask05515    5      1-------------      #→ Conversion binary 101  101  001     #→umask Binary-------------      #→ and Operation 110  110  110       #→ file maximum permissions binary-------------     100  100  000----------- --      #→ convert octal 4    4    0 Description: The last obtained value is 440, Then use 666 minus 440, then the file creation permission is 226.



1.5 Description of permissions between servers in the enterprise

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/92/E8/wKioL1kE1B2R-fM4AANAHsRJw7A457.png "title=" QQ picture 20170429225953.png "alt=" Wkiol1ke1b2r-fm4aanahsrjw7a457.png "/>



The relationship between Umask value and file and directory permissions in Linux

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.