TechEarl

Linux umask Explained (Default Permissions)

How umask subtracts from 666 and 777 to set the permissions new files and directories are born with, how to read it, and how to change it for a session or for good.

Ishan Karunaratne⏱️ 3 min readUpdated
Share thisCopied
How the Linux umask subtracts from 666 and 777 to decide the permissions new files and directories are created with, and how to change it.

chmod sets the permissions on a file that already exists. umask decides the permissions a new file is born with. It is a mask of bits to remove from the system defaults.

bash
umask          # show the current mask, e.g. 0022
Terminal showing umask output 0022, a new file created at 644, then umask 077 and a new file created at 600, demonstrating how the mask removes permission bits.
With umask 022 a new file is 644; with umask 077 it is 600. The mask is subtracted from the base mode.

The math

The base mode is 666 for files and 777 for directories (the system never grants execute on a new file automatically). The umask is subtracted from that:

umaskNew file (666 - mask)New dir (777 - mask)Who gets the new file
022644755owner writes, others read (the common default)
002664775owner and group write, others read (shared teams)
077600700owner only (private, good for sensitive work)
027640750owner writes, group reads, others nothing

So a umask of 022 is why your new files come out 644 and your new directories 755. It is not arithmetic subtraction exactly (it is a bitwise clear), but for the usual values it reads like subtraction.

Change it for this session

bash
umask 077        # everything you create now is owner-only
touch secret.txt # -> 600

The change lasts until the shell exits. It affects only files created after you set it, not existing ones.

Change it for good

Per-user, add it to your shell startup (~/.bashrc, ~/.zshrc, or ~/.profile):

bash
echo 'umask 077' >> ~/.bashrc

System-wide defaults live in /etc/login.defs (UMASK) and /etc/profile. A tighter umask is a cheap, broad hardening win, especially on shared machines: set 077 and new files are private by default instead of world-readable.

FAQ

See also

Sources

Authoritative references this article was fact-checked against.

TagsLinuxumaskFile PermissionsShellSystem Administration

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Tech Architect · Software Engineer · AI/DevOps

Tech architect and software engineer with 20+ years building software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Currently Chief Technology Officer at a healthcare tech startup, which is where most of these field notes come from.

Keep reading

Related posts

SQL Injection: Variants, Exploitation, and Defence

How SQL injection actually works, what every major variant looks like (union-based, error-based, boolean blind, time blind, out-of-band, second-order, NoSQL), how to exploit each one against a vulnerable app, and how to defend against them at the code, query, and infrastructure layers.