Umask is a system variable that, when a file is created, sets a mask for the access rights of the file. You can modify the value of this variable by executing the umask command. It is a value consisting of 3 octal digits. Each number is the result of an octal value of 1, 2, or 4. Their specific meanings are shown in the table below. Three of these numbers correspond to the access rights of the user, group, and other users (other).
Digital |
Take value |
Meaning |
1 |
0 |
Allow any permission to be owned by the owner |
|
4 |
Prohibit read access to the owner |
|
2 |
prohibit write permission of the owner |
|
1 |
Prohibit owner's execution rights |
2 |
0 |
Allow group any permissions |
|
4 |
Prohibit read permissions for a group |
|
2 |
Prohibit Write permissions for groups |
|
1 |
Prohibit execute permissions for a group |
3 |
0 |
Allow any permissions for other users |
|
4 |
Prohibit Read permissions for other users |
|
2 |
Prohibit write permissions for other users |
|
1 |
Prohibit execution rights for other users |
Understanding: Each octal with a three-bit binary number to represent the----RWX, where, if r=1, the Read permission is forbidden, if w=1, the Write permission is forbidden, if the x=1, then the execution permission is forbidden. This is the exact opposite of the octal usage in the chmod command.
When a file is created through an open or creat call, the mode parameter is compared to the current umask value. The bit set in the mode parameter, if it is also set in the Umask value, is removed from the file's access permissions. As a result, users can fully set their own environment, such as "not allowed to create files that allow other users to have write permissions, even if the program that created the file requires that permission." "This does not make it possible for a program or user to use the chmod command later (or to use a chmod system call in a program) to add write permissions to other users, but it is able to help the user so that they do not have to check and set their access permissions on each new file.
Notes on umask system variables in Linux