Umask Basics
What is UMASK
UMASK is known as User Mask which is responsible for deciding permissions on files and directories that gets created.
Default UMASK Values for Files and Directories
In most of the systems you will see a default umask value of 0022 for all files and directories.
How to Calculate Files and Directories Permissions Based on UMASK Value
As you might be aware, base permission of a file is 0666 and base permission of a directory is 0777. Hence final permission of files and directories will get calculated from this base permission values. If umask is set to 0022 in the system, then creating a file and directories will have below permission.
666 with a umask of 022 becomes 644 on any child files
For Files : 0666 - 0022 = 0644
For Directories: 0777 - 0022 = 0755
If umask is set 0032, then creating file and directories will have below permission.
For Files: 0666 - 0032 = 0634
For Directories: 0777 - 0032 = 0745
How umask Masks Out Permissions
Subtracting the mask value from the default permissions gives you the actual permissions. In other words, if a permission is set in the umask value it will not be set in the permissions applied to the directory or file.
The umask values work as an inverse of the usual permission values.
- 0: No permissions are removed.
- 1: The execute bit is unset in the permissions.
- 2: The write bit is unset in the permissions.
- 4: The read bit is unset in the permissions.
Setting umask on a directory
Umask cannot be set on a directory, you would use FACL