What Is Umask In Linux and How To Set Umask?

Linux files and directories have access to privileges or rights in order to allow or prevent different users. These permissions consist of reading, write, and execute in basic. There are also some extra permissions. The umask is the expression of these permissions in numerical or symbolic format and also the command which can be used to set default permissions for files and directories.

Calculate Umask

Umask is calculated by reversing the regular permissions of the file and directory. For example, the file 664 permission and directory 775 are expressed as 002 as a umask value.

Read, Write and Execute0
Read and Write1
Read and Execute2
Read (Read-Only)3
Write and Execute4
Write (Write-Only)5
Execute (Execute-Only)6
No Permission7
Umask Permission Calculation

Print Umask Value In Bash Shell

The umask command is can be executed in order to print the current umask value.


The output is like below which contains 4 digits.


Set Umask Value with umask Command

The Umask value can be set with the umask command by providing the value. In the following example, we will set the Umask value as 0003.

umask 0003

Set umask for the Current User

The umask for the current user can be set in different ways. For example, the .bashrc file which is located under the current user home directory can be used to set umask. First, open the ~/.bashrc and put the following line at the end of the line. This configuration also makes the Umask value persistent where even the system reboots the value stays the same.

umask 022

But this configuration file is used for bash shell. For different Linux shells use the following files which work the same.

  • Korn Shell: ~/.profile
  • C Shell: ~/.cshrc
  • Bash: ~/.bash_profile

Set Umask for All Users

Also, we can set the umask value for all users in the current Linux system. The /etc/profile file is a bash shell configuration file that is loaded when a user starts the bash shell. This configuration file is applied to all users.

umask 022

Leave a Comment