Walker News

How To Use umask To Set Linux File And Directory Default Permission?

You may aware that the Linux umask command defines default permission of file and directory created by a process.

So, how to configure or set the umask? The following reference is based on Redhat Linux (RHEL), but should be applicable to most “modern” Linux distributions (and probably UNIX too):
By convention, the highest “default” permission of file is 666 (read and write permission for all user accounts, regardless umask setting actually grants execute permission). For directory, however, the highest “default” permission is 777 (read, write, and execute permission for all user accounts).

To verify or check umask setting of current user account, just type “umask” or “umask -S” (ignore the first digit of umask value, which is not interest of this topic – that is for setuid, setgid, and sticky attributes):
[walker@localhost]$ umask
[walker@localhost]$ umask -S

To change umask settings, e.g. change file and directory default permission to 600 and 700 respectively:
[walker@localhost]$ umask -S u=rwx,g=,o=
[walker@localhost]$ umask
[walker@localhost]$ touch test_file
[walker@localhost]$ ls -l test_file
-rw------- 1 walker walker 0 Jan 30 00:01 test_file
[walker@localhost]$ mkdir test_folder
[walker@localhost]$ ls -la test_folder
total 8
drwx------  2 walker walker 4096 Jan 30 00:02 .
drwxr-xr-x 13 walker walker 4096 Jan 30 00:02 ..

NOTE: If you execute umask at Linux command prompt to change file and directory default permission, this new umask setting will be discarded as soon as you log out.

Thus, for persistent setup, either fix the umask setting in respective user account login script (e.g. $HOME/.bash_profile) or system profile (e.g. /etc/bashrc).

Custom Search

2017  •  Privacy Policy