umask
--Indicates the default permissions when creating a file (that is, it does not need to be set when creating a file)
For example, we found
under root user , touch A, the default permission for file A is 644
under Normal user , touch B, the default permission for file B is 664
644 and 664 We are not set, and the key factor is umask
Analysis:
|
directory |
file |
highest privilege |
777 RWXRWXRWX |
666 rw-rw-rw- |
command umask can view the current user's umask value
|
Root |
Normal User |
Umask |
022 |
002 |
in combination with the above examples, we know:
Default permissions = Maximum permissions-umask(644=666-022//664=666-002)
but:
when Umask is 011, the default permission to create a file should be 6 55, but the default permissions are 666 when actually running
666-rw-rw-rw-
011,-----x--x
to subtract:
666 <-rw-rw-rw-
(This special case only appears in the file because the file [except the binary file] does not have x Execute permission)
So, when viewing the umask of a file, we pay special attention to whether there is an odd digit (x = 1)
umask + value Modify the current user's umask such as: Umask 044
However, this set of umask will restore the original value when the user logs back in, we can save the modified umask in ~/.BASHRC
***************************
Vim ~/.BASHRC
Add umask at the end of the file 044
Save exit
Re-login user is saved successfully
***************************
Case:
Liu closed three brothers belong to Shu this additional user group, has a shared directory, called Shuguo, three brothers in Shuguo under the creation of files, can be modified between each other. Other people without any permission, the three brothers created files can only be deleted by themselves. (default setting by Umask value)
Groupadd Shu
useradd-g shu Liubei
useradd-g shu Guanyu
useradd-g shu Zhangfei
mkdir Shuguo
chgrp shu shuguo/ /*shuguo directory belongs to the group changed to shu*/
chmod g+s shuguo/ / * Make Liu closing files created by shu*/
chmod o+t shuguo/ / * Make Liu closed the files created can only be deleted by themselves * /
chmod g+w shuguo/ /* Make Liu Closure can modify and execute files under Shuguo */
umask 006
Linux Learning-umask Detailed