Gangmax Blog

What is Umask and How To Setup Default umask Under Linux?

Today I notice that the new directory is created with “775” permission by default on my Ubuntu. Why? So here comes this post. From “here“.

When user create a file or directory under Linux or UNIX, she create it with a default set of permissions. In most case the system defaults may be open or relaxed for file sharing purpose. For example, if a text file has 666 permissions, it grants read and write permission to everyone. Similarly a directory with 777 permissions, grants read, write, and execute permission to everyone.

Default umask Value

The user file-creation mode mask (umask) is use to determine the file permission for newly created files. It can be used to control the default file permission for new files. It is a four-digit octal number. A umask can be set or expressed using:

  • Symbolic values

  • Octal values

Procedure To Setup Default umask

You can setup umask in “/etc/bashrc” or “/etc/profile” file for all users. By default most Linux distro set it to “0022(022)”” or “0002(002)”. Open “/etc/profile” or “~/.bashrc” file, enter:

1
# vi /etc/profile

OR:

1
$ vi ~/.bashrc

Append/modify following line to setup a new umask:

1
umask 022

Save and close the file. Changes will take effect after next login. All UNIX users can override the system umask defaults in their “/etc/profile” file, “~/.profile” (Korn/Bourne shell), “~/.cshrc” file (C shells), “~/.bash_profile” (Bash shell) or “~/.login” file (defines the user’s environment at login).

Explain Octal umask Mode 022 And 002

As I said earlier, if the default settings are not changed, files are created with the access mode 666 and directories with 777. In this example:

  1. The default umask 002 used for normal user. With this mask default directory permissions are 775 and default file permissions are 664.

  2. The default umask for the root user is 022 result into default directory permissions are 755 and default file permissions are 644.

  3. For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666 (rw-rw-rw).

Comments