The umask (user file creation mask) in Linux affects the default permissions assigned to newly created files and directories. It specifies which permission bits should be "masked out" or removed when a file or directory is created. Here's how it works:
-
Default Permissions:
- For directories, the default permissions are typically
777(rwxrwxrwx). - For files, the default permissions are typically
666(rw-rw-rw-), since files do not usually need execute permissions by default.
- For directories, the default permissions are typically
-
Applying umask:
Theumaskvalue is subtracted from the default permissions to determine the actual permissions for the newly created file or directory. Theumaskvalue is specified in octal format.For example:
-
If the
umaskis set to022, the permissions for a new directory would be calculated as follows:- Default permissions for a directory:
777 - Subtract
022(umask):777 - 022 = 755 - Resulting permissions:
755(rwxr-xr-x)
- Default permissions for a directory:
-
For a new file with the same
umask:- Default permissions for a file:
666 - Subtract
022(umask):666 - 022 = 644 - Resulting permissions:
644(rw-r--r--)
- Default permissions for a file:
-
-
Common umask Values:
000: No restrictions; files and directories are created with full permissions.022: Common default; allows the owner full permissions while restricting group and others to read and execute.027: Restricts group access; owner has full permissions, while group has no write access.
You can check the current umask value by running:
umask
To change the umask value for the current session, you can use:
umask new_value
Understanding umask is important for managing file and directory permissions effectively in a multi-user environment.
