In Linux everything treats as a file. In most Linux distros User Mask is the default permission whenever we create new file and folder/directory in Linux system. So we can say UMASK is the Linux system default permission for created file and directory. Default UMASK is 022 (0022) in Linux.
CHECKING USMASK IN LINUX
Value of UMASK is same for fine and directory in Linux, but its calculations are different.
000 and 777 is the minimum and maximum UMASK value for folder in Linux.
000 and 666 is the minimum and maximum UMASK value for file in Linux.
The question is why 666 max value for file in Linux.
Because of binaries and scripts have execute permission in Linux. Normal file have read and write permission.
777 is the max value for directory because directory require execute permission for listing and viewing the directory contents.
Below you can see in chart these are inverse to actual permissions value during permission setup for file and directory using chmod command in Linux.
CHECKING DEFAULT UMASK VALUE IN LINUX
If you want to check default UMASK value in Linux system just type “umask” command.
# umask 0022
Above you can see default UMASK value is 0022
CHANGING DEFAULT UMASK VALUE FOR ALL NEWLEY CREATE USERS
You can set UMASK value in “/etc/profile” file for all new users. You will need to root access to change UMSK value and write below line in the file.
CHANGING DEFAULT UMASK VALUE FOR EXISTING USERS
You will need to edit “ ~/.bashrc” file to change existing user UMASK value in their home directory.
If you have lots of users on your system you will need to change one by one for all users or alternatively you can create a shell scripts.
DIFFERENCE BETWEEN 0022 AND 022 UMASK VALUE
For your kind information there are no difference between 0022 and 022 umask value because preceding 0 means there is no sticky bit,suid and sgid information is set.
PREFERRED UMASK VALUE FOR SYSTEM SECURITY PURPOSE
For security purpose default UMASK value should be 027 (0027). It will disallow others users not to read,write and execute file and directory.
FOR MORE INFO ABOUT UMASK USE LINUX MAN AND INFO PAGE
#man umask #info umask
I hope this article will be helpful to understand UMASK value in Linux. If you have any queries and problem please comment in comment section or you can also ask your question.