What is UMASK and how to set UMASK in Linux/Unix?

Post your How to's here

What is UMASK and how to set UMASK in Linux/Unix?

Postby tanmay.01 » Tue Apr 23, 2013 11:24 pm

UMASK(User Mask or User file creation MASK) is the default permission or base permissions given when a new file(even folder too, as Linux treats everything as files) is created on a Linux machine. Most of the Linux distros give 022(0022) as default UMASK. In other words, It is a system default permissions for newly created files/folders in the machine.

How to calculate UMASK in Linux?

Though umask value is same for files and folders but calculation of File base permissions and Directory base permissions are different.

The minimum and maximum UMASK value for a folder is 000 and 777

The minimum and maximum UMASK value for a file is 000 and 666

Why 666 is the maximum value for a file?
This is because only scripts and binaries should have execute permissions, normal and regular files should have just read and write permissions. Directories require execute permissions for viewing the contents in it, so they can have 777 as permissions.

Below are the permissions and its values used by UMASK. If you are a Linux/Unix user you will observe these are inverse to actual permissions values when setting up permissions to files/folders with CHMOD command.

0 --Full permissions(Read, Write, Execute)
1 --Write and read
2 --Read and execute
3 --Read only
4 --Write and execute
5 --Write only
6 --Execute onlyadminadmin
7 --No permissions

How to remember these and calculate the file and folder permissions?
Consider above values are inverse to actual permissions. Suppose your UMASK value is 0027(027).

For folder:
To calculate actual folder permissions from UMASK is done in two steps

Step1:Logical Negate the UMASK

Not(027) = 750

Step2: Logical AND this number with 777

777 AND 750 = 750

So actual folder permissions is 750 when its created. Owner will get full permission, group gets execute and write permissions and others no permissions

In other words and simple way..
We have to subtract 027 from 777 then we will get the actual folder permissions.

777 - 027 = 750

which is nothing but full permissions for the owner, read and execute permissions for group and no permissions for others.

For files:
To get actuall file permissions from UMASK is done in two steps

Step1:Logical Negate the UMASK

Not(027) = 750

Step2: Logical AND this number with 666

666 AND 750 = 640

For your understanding purpose we have calculated this below equation to get what actuall AND operator do.

110 + 111 = 110(6)
110 + 101 = 100(4)
110 + 000 = 000(0)

How to see default UMASK?
just type umask and you will get whats the default UMASK




Some FAQ related to umask:

1)How to setup or change default UMASK for all the new users?
The UMASK value can be set in /etc/profile for all the new users. Open this file as root user and given the below line in the file.

umask 027

2)How to setup or change default UMASK for existing users?
For existing users you can edit ~/.bashrc file in their home directory. This should be done for all the users one by one or if the machine is having lots and lots of users then you can write a shell script for this.

3)I see people are using 0022 and 022 as UMASK, is there any difference between them?

There is no difference between these two, both indicates one and the same. The preceding 0 indicates there is no SUID/SGID/Sticky bit information set.

4)What is the perferred UMASK value for a system for Security reasons?

Prefered is 027(0027) for security reasons becasue this will restrict others not to read/write/execute that file/folder

5)I see umask value as 022 in my vsftpd config file? what actually this mean to world?

When you see 022 as umask value in vsftpd config file that indicates that users who are going to create files will get 644 and for folders its 755 respectively.

To know more about umask refer man pages and info pages.

Code: Select all
man umask

info umask
•3rd generation Intel(R) Core(TheeMahn) i5-3210M Processor (2.5 GHz with Turbo Boost up to 3.1 GHz)
• 1GB Radeon(TheeMahn) HD 7750M GDDR5 Graphics [HDMI]
• 6GB 1600DDR3 System Memory (2 Dimm)
• 750GB 7200 rpm Hard Drive
• Intel 2x2 802.11a/b/g/n WLAN + Bluetooth(R)
• Full-size Radiance backlit keyboard.

User avatar
Posts: 253
Joined: Wed Dec 07, 2011 1:03 pm
Location: India
Age: 27
Operating System: Other Linux

Re: What is UMASK and how to set UMASK in Linux/Unix?

Postby pam » Tue Apr 23, 2013 11:37 pm


Download Ultimate Edition and Oz Unity 3.0 from copy:-
Download Ultimate Edition from sourceforge:-
http://sourceforge.net/projects/ultimat ... rce=navbar
Download Oz Unity 3.0 from sourceforge:-
Download Ultimate Edition torrents from linuxtracker:-
http://linuxtracker.org/index.php?page= ... 0&active=1
Download Oz Unity 3.0 torrents from linuxtracker:-
http://linuxtracker.org/index.php?page= ... 0&active=1
Image Image
User avatar
Site Admin
Posts: 1087
Joined: Wed May 25, 2011 5:56 am
Location: India
Age: 32
Operating System: Ultimate Edition 3.5 64 BIT

Re: What is UMASK and how to set UMASK in Linux/Unix?

Postby ryanvade » Wed Apr 24, 2013 10:45 am

Cool stuff.

Laptop: HP dv6t-7000 CTO Desktop: Compaq Presario SR21632wm
i5 2450m Pentium D 960 @ 4 GHz
6 GB ram 2 GB ram
Intel HD 3000 Graphics / Nvidia GT 630M Nvidia GT 520 @ 820 MHz
Diamond II-B 3.10-rc4/Windows 7 Home Premium KDE | Windows 7 Starter/Arch Linux

Paid supporter of the Linux Foundation
User avatar
Posts: 499
Joined: Sat Apr 28, 2012 10:54 am
Operating System: Other Linux

Return to How To's (Do not post questions please)

Who is online

Users browsing this forum: No registered users and 0 guests