linux An in depth understanding of umask's new file permission Settings
- 2021-01-06 00:50:24
If your umask is set to 022, what is the default file permission you create?
This reminds me of another question I was asked: What permission does 777 represent?
User Group Description
The first character represents file (-), directory (d), link (l) The remaining characters are in groups of 3 (rwx), read (r), write (w), execute (x). Group 1 rwx: The permissions of the file owner are read, write, and execute rw- : Users in the same group as the file owner can read, write, but not execute Group 3 r-- : Other users who are not in the same group as the file owner have permissions to read and not write and execute It can also be expressed numerically: r=4, w=2, x=1, because rwx represents a 3-bit binary system, which is exactly the number to calculate.
-rwxrw-r � -1 root root 1213 Feb 2 09:39 abc
Description of Digital Permission
777 is a 3-digit octadecimal number, corresponding to 111111111, which means that all three groups can be read, written, and executed. We can use it like this:
chmod 755 abc //chmod Change the file abc The permissions for the file owner are readable, writable and executable, and the same group and other group users are readable and executable
umask is the permission mask, which represents the default permissions not to be used. It calculates the default permissions for the user to create new objects based on the maximum default value of 666 and the folder 777.
For example, in question 1, the default permission to create a file is 666-022=644, which is -rw -r --r
What is the umask used for
The default umask value is 022(umask), and the default permissions are 644(6-0,6-2,6-2). The default permissions are 755(7-0,7-2,7-2). You can use ls-l to verify this.
[root@bogon test]# id uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 [root@bogon test]# umask [root@bogon test]# touch a.txt [root@bogon test]# ls -l total 0 -rw-r--r--. 1 root root 0 Jul 3 00:40 a.txt [root@bogon test]# mkdir b [root@bogon test]# ls -l total 0 -rw-r--r--. 1 root root 0 Jul 3 00:40 a.txt drwxr-xr-x. 2 root root 6 Jul 3 00:41 b
As you can see from above, umask of root is 022(the first 0 represents the special permission bit, which is not considered here), the default permissions for the files created are 644, and the directory created is 755.
Before we look at the use of umask, we need to explain the basic file permissions