umask Explained: Why 022 Gives 644 and Directories 755
A umask is a mask of bits to remove from the mode a program asks for when it creates a file or directory. Programs normally ask for 666 for files and 777 for directories. The umask calculator does the subtraction.
| umask | New files | New directories | Typical use |
|---|---|---|---|
| 022 | 644 | 755 | Default on most distributions |
| 002 | 664 | 775 | Shared group directories (some distributions default to this for user-private groups) |
| 027 | 640 | 750 | Others get nothing |
| 077 | 600 | 700 | Private by default |
The operation is mode AND NOT umask. It can only clear bits, never set them: files do not become executable because files start from 666, not 777. That is why a script you create needs an explicit chmod +x.
What it does not affect
chmodwith an octal mode sets exactly that mode and ignores the umask.chmod +x-style symbolic changes do consult it when nou,g,oorais given. The symbolic calculator models this: under umask 022,chmod +wadds write for the owner only.- Files copied with
cp -por extracted withtar -pkeep their original modes. - ACL default entries on a directory can override the umask for files created inside it.
From a wanted mode to a umask
Take the directory mode you want and subtract it from 777. For 750 the umask is 027. The calculator's second panel does this and also shows the file mode that results (the same minus execute bits).
Where it is set
A shell's umask comes from the login scripts (/etc/profile, ~/.profile), PAM (pam_umask), or a service manager (UMask= in a systemd unit). A service that creates files with unexpected modes usually inherited a different umask than your shell has.