Linux Command Reference ยท Permissions and Users
Linux umask command
Reference for the Linux umask shell builtin: how the mask removes permission bits from new files and directories, octal and symbolic forms, and common values.
umask sets the file mode creation mask of the shell: the permission bits that are removed from every new file and directory. Programs ask the kernel to create files with a requested mode (usually 666 for files, 777 for directories), and the kernel clears the bits that are set in the mask. The mask is inherited by child processes, so setting it in a shell affects every command you run from then on.
With no argument umask prints the current mask. It is a shell builtin, because the mask belongs to the shell process itself; a separate program could not change it.
umask 027
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
umask [-p] [-S] [MODE]
| Name | Description |
|---|---|
MODE (octal) |
Bits to remove, for example 022. |
MODE (symbolic) |
Permissions to allow, for example u=rwx,g=rx,o=rx. |
-S |
Print the current mask in symbolic form (the allowed permissions). |
-p |
Print the mask as a command that can be re-run, umask 0022. |
Returns: 0, or non-zero for an invalid mode.
Errors: invalid octal number or invalid symbolic mode operator for a bad argument.
Usage notes
- Subtract bit by bit, not numerically. A mask of
027removes write from the group and everything from others. Files start from 666:666 & ~027 = 640; directories from 777:750. - Files never get execute bits from the mask, because programs request 666 for ordinary files. Scripts become executable only with
chmod +x. - Common values:
022(default on most distributions: group and others can read),002(user-private group setups: group can also write),077(private: only you),027(group may read, others nothing). - Octal versus symbolic is inverted.
umask 022andumask u=rwx,g=rx,o=rxmean the same thing: the octal names what to remove, the symbolic form names what to keep. - Where to set it permanently:
~/.bashrcor~/.profilefor one user,/etc/profileor/etc/login.defs(UMASK) system-wide, andpam_umaskon systems that use it. Services started by systemd useUMask=in the unit. - Scripts that create secrets (keys, tokens) should run
umask 077first or create files withinstall -m 600, so there is no window where the file is readable. chmodignores the mask. The mask applies to creation only. Symbolicchmod +wwithout au/g/oletter does consult it.- Directories shared by a group usually need
umask 002plus the setgid bit on the directory. - Mask is per process. A subshell, a script and a program all inherit the value, but cannot change the parent's.