breakitdown

umask 022

Answer

With umask 022, new files are created with mode 644 (rw-r--r--) and new directories with 755 (rwxr-xr-x). The 2s remove write permission for group and others; everything else the program asked for is kept.

What umask 022 gives

New files
644 rw-r--r--
New directories
755 rwxr-xr-x
umask -S
u=rwx,g=rx,o=rx

What to know

A umask lists the bits to remove from new files. Programs normally request 666 for files and 777 for directories, and the kernel clears every bit that is set in the umask: 666 becomes 644 and 777 becomes 755. Files never get execute from the umask; that has to be added with chmod.

022 is the default in /etc/login.defs on Debian and Ubuntu and is the usual umask for root and for system services. Run umask to see yours, or umask -S for the symbolic form (u=rwx,g=rx,o=rx).

Gotchas

Related explainers

← chmod calculator