Linux: Linux user permissions

Published by

Posted on November 23, 2008

If you ever wondered how does linux set the default permissions on files and folders. Then you have come to the right place. if you issue the umask command via shell it will show you the default permissions in a octal format . using the umask -S will show you the symbolic format of the permissions.

I found a site that goes into great detail at Man pages

============= Umask ==========
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 .
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 (global) or ~/.bashrc file

But what is 0022 and 0002?
The default umask 0002 used for normal user. With this mask default directory permissions are 775 and default file permissions are 664.
The default umask for the root user is 0022 result into default directory permissions are 755 and default file permissions are 644.
For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666 (rw-rw-rw).
To calculate file permission for 022 (root user):
Default Permissions: 777
Subtract umask value: 022 (-)
Allowed Permissions: 755
To calculate directory permission for 022 umaks (root user):
Default Permissions: 666
Subtract umask value: 022 (-)
Allowed Permissions: 644
The following example explains the steps needed to set umask for permissions 700 for user files. The idea very simply only user is allowed to read or write file.
Default Permissions: 777
Subtract umask value: 077 (-)
Allowed Permissions: 700