Linux Administrator

What is UMASK and How to Set UMASK in Linux?

In this tutorial I will explain What is UMASK and How to Set UMASK in Linux.

What is UMASK and How to Set UMASK in Linux

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.

You may also like : How to set umask in Apache?

CHECKING USMASK IN LINUX

Value of UMASK is same for fine and directory in Linux,  but its calculations are different.

FOLDER UMASK

000 and 777 is the minimum and maximum UMASK value for folder in Linux.

FILE UMASK

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.

 umask-table

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.

Umask 027

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.

Thanks:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

1 Comment

Leave a Comment