Skip to content
Tutorials Center
My learning

Topics

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.

Terminal
umask 027

Try it

Bash How the mask shapes new files

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.

Bash The arithmetic, and umask in a subshell

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

Terminal
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 027 removes 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 022 and umask u=rwx,g=rx,o=rx mean the same thing: the octal names what to remove, the symbolic form names what to keep.
  • Where to set it permanently: ~/.bashrc or ~/.profile for one user, /etc/profile or /etc/login.defs (UMASK) system-wide, and pam_umask on systems that use it. Services started by systemd use UMask= in the unit.
  • Scripts that create secrets (keys, tokens) should run umask 077 first or create files with install -m 600, so there is no window where the file is readable.
  • chmod ignores the mask. The mask applies to creation only. Symbolic chmod +w without a u/g/o letter does consult it.
  • Directories shared by a group usually need umask 002 plus 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.