Skip to content

UMASK in linux

What is Umask?

  • umask (user file-creation mode mask) determines the default permissions assigned to new files and directories when they are created.
  • It works by subtracting these values from the maximum possible permissions.

Default Maximum Permissions

  • Files: 0022
  • Directories: 755
Terminal window
pavan@EPINHYDW1828:~$ touch EXAMPLE
pavan@EPINHYDW1828:~$ mkdir -p EXAMPLE2
pavan@EPINHYDW1828:~$ ls -ltr
-rw-r--r-- 1 pavan pavan 0 Mar 23 17:52 EXAMPLE
drwxr-xr-x 2 pavan pavan 4096 Mar 23 17:52 EXAMPLE2
pavan@EPINHYDW1828:~$ umask
0022
pavan@EPINHYDW1828:~$ umask -S
u=rwx,g=rx,o=rx

CommandDescription
umaskCheck the current umask value in octal format.
umask -SCheck the current umask in symbolic format (e.g., u=rwx,g=rx,o=rx).
umaskTemporarily set a new umask value (e.g., umask 0022).
source ~/.bashrcApply changes to umask made in the .bashrc file immediately.

  • To see your current umask setting: umask
    • Output example: 0022
  • To see the human-readable default permissions: umask -S
    • Output example: u=rwx,g=rx,o=rx
  • If umask is 022, new files are calculated as 666 - 022 = 644.
    • File Permissions: 644 (rw-r--r--)

3. Temporarily Changing Default Permissions

Section titled “3. Temporarily Changing Default Permissions”
  • To remove write permissions for the group and others for new files: umask 0022

4. Permanently Changing Default Permissions

Section titled “4. Permanently Changing Default Permissions”
  • To make changes permanent, add the umask command to your shell configuration file (e.g., ~/.bashrc or ~/.profile).
    1. Edit the file: nano ~/.bashrc
    2. Add line at the end: umask 0077 (This makes files private to the user only).
    3. Apply changes: source ~/.bashrc

5. Modifying Specific Permissions (Symbolic Mode)

Section titled “5. Modifying Specific Permissions (Symbolic Mode)”
  • Instead of calculating numbers, you can directly set permissions for users (u), groups (g), or others (o).
  • To remove read permissions for others for new files: umask o-r