The simplest way to calculate umask values and file directory permissions
Permissions for directories created by default in Linux are 755
[Email protected] data]# mkdir a
[email protected] data]# LL
Total 4
Drwxr-xr-x. 2 root root 4096 Apr 13:09 a
Permissions for files created by default in Linux are 644
[email protected] data]# Touch a.txt
[email protected] data]# LL
Total 4
-rw-r--r--. 1 root root 0 Apr 13:11 a.txt
The value of umask in cent OS 6.5 is 0022
But there is a premise: there is a word in/etc/profile:
If [$UID-gt 199] && ["' id-gn '" = "' Id-un '"]; Then
Umask 002
Else
Umask 022
Fi
So my user root, his default umask value is 0022.
[Email protected] data]# ID-GN
Root
[Email protected] data]# Id-un
Root
The Umask permission for the/home directory in Linux is 077, which is clearly stated in the/etc/login.defs
[Email protected] home]# LS-LD test
DRWX------. 2 test test 4096 APR 7 22:46 test
The simplest method: "Add and Subtract"
1, when the umask value of each bit is an even number:
How to calculate the file: The maximum permission is calculated as 666来.
Example: Set the Umask value to 066
[Email protected] data]# umask 066
[Email protected] data]# umask
0066
[[email protected] data]# Touch 066file
[Email protected] data]# ls-l 066file
-RW-------. 1 root root 0 Apr 13:32 066file
Solution: 666-066=600 600 is the permission for this file.
How to calculate a directory: The maximum permissions are calculated as 777来.
[Email protected] data]# umask 044
[Email protected] data]# umask
0044
[Email protected] data]# mkdir 044dir
[Email protected] data]# ls-ld 044dir
Drwx-wx-wx. 2 root root 4096 Apr 13:34 044dir
Solution: 777-044=733 733 is the maximum permission for this directory.
2, when the umask value of each bit is odd:
How to calculate the file: 666 for maximum permissions
Example: Change Umask to 043
[Email protected] data]# umask 043
[Email protected] data]# umask
0043
[[email protected] data]# Touch 043file
[Email protected] data]# ls-l 043file
-rw--w-r--. 1 root root 0 Apr 13:39 043file
Solution: 666-043=623 add 1 to odd digits =624
How to calculate a directory: 777 for maximum permissions
Example: Change Umask to 043
[Email protected] data]# umask 043
[Email protected] data]# umask
0043
[Email protected] data]# mkdir 043dir
[Email protected] data]# ls-ld 043dir
DRWX-WXR--. 2 root root 4096 Apr 13:39 043dir
Solution: 777-043=734 This does not affect ha.
Summarize:
Each bit of the umask value is an even number:
File permissions calculation method: 666 minus the Umask value
Permission calculation method for directory: 777 minus umask value
When the Umask value is odd:
File permissions calculation method: 666 minus the umask value, and then on the basis of the result, on the umask of the odd digits +1
Permissions for the directory calculation method: 777 minus the Umask value, the directory does not affect
How to calculate file and directory permissions Umask