Umask

Umask.

 

Describe in details about umask.?

User Mask

New files should not be created with 666! To avoid this problem a permission mask exists. It is obviously important to know with what permissions new files and directories are created. Under Linux, it’s not really easy to tell, since the default permissions can be modified by setting a umask (with the umask command).

 

If no umask were set (which never happens, by the way), a file would always be created with permissions 666 (rw-rw-rw-) and a directory would get 777 (rwxrwxrwx). In actual practice however, a umask is set, and this number is subtracted from these permissions.

 

So, with a umask of 022, the default permissions for a file will become 644 (rw-r–r–, 666-022) and the default permissions for a directory will become 755 (rwx-r-xr-x, 777-022). The default umask depends on your distribution, and whether your

distribution uses something called “User Private Groups”.

 

  1. How to configure umask for a user?

From here I figured easy step how to set umask mode to 0027 just run in terminal:

sudo gedit /etc/login.defs

or with nano which one you prefer.

search for the line:

Prefix these values with “0” to get octal, “0x” to get hexadecimal. ERASECHAR 0177 KILLCHAR 025 UMASK 027

Edit the last line refering UMASK this will set umask to 0007 to take effect simply log out and log in back.

Make a notice on the lines above: If USERGROUPS_ENAB is set to “yes”, that will modify this UMASK default value…used as group permissions, e. g. 022 will become 002

So for the umask 0027 to take effect roll down to the line:

USERGROUPS_ENAB yes

and change it to:

USERGROUPS_ENAB no

Done. After you logged out and log in back run in terminal umask and it’ll give you 0027 mode.

Now create a new file with touch in terminal:

touch testfile

now check the permissions:

stat -c %a ~/testfile

It should give you 640

 

Advertisements