umask (user file-creation mode mask) is a per-process bit mask that tells the Linux kernel which permission bits to remove from every new file and directory a process creates. It does not change existing files; it only shapes the default permissions that new objects receive, which makes it the quiet first line of access control in Linux permissions.
Every process inherits its umask from its parent, so a value set in a login shell, a service unit or a container entrypoint silently governs everything that process writes. Understanding the umask explains why a freshly created file is usually 644 rather than 666, and why shared directories and service output sometimes end up with surprising access rights.
How the umask removes permission bits
The umask works by clearing bits, not by subtracting numbers. When a program calls open(), creat() or mkdir(), it passes a requested mode. The kernel computes the final mode as requested mode AND NOT umask, so any bit that is set in the umask is switched off in the result.
Most programs request `0666` for regular files and `0777` for directories. Execute permission is deliberately left out of the file request, because a new file should not be executable by accident. With the common umask of 022, the group and others lose write permission, producing `644` files and `755` directories.
The following table shows how typical umask values translate into the default permissions of new files and directories when programs use the standard requested modes.
| Umask | New file | New directory | Typical use |
|---|---|---|---|
| 022 | 644 (rw-r–r–) | 755 (rwxr-xr-x) | Traditional system default |
| 002 | 664 (rw-rw-r–) | 775 (rwxrwxr-x) | User private groups, team work |
| 027 | 640 (rw-r—–) | 750 (rwxr-x—) | Hardened servers |
| 077 | 600 (rw——-) | 700 (rwx——) | Private data, secrets |
| 007 | 660 (rw-rw—-) | 770 (rwxrwx—) | Group-only project areas |
Because the operation is a bitwise mask, arithmetic intuition can mislead. A umask of 033 applied to a file request of 0666 yields 644, not 633, because the execute bits it tries to remove were never requested. Thinking in bits avoids this common error.
Where the umask value comes from
The effective umask is inherited through `fork()` and preserved across exec(), so its value depends on the chain of processes that started a program. Several layers can set or override it, and the last one applied wins for that process and its children.
| Layer | Mechanism | Scope |
|---|---|---|
| Kernel default | Initial value 0022 for init | All processes unless changed |
| PAM module | pam_umask reading UMASK in /etc/login.defs | Login sessions |
| Shell startup files | umask builtin in /etc/profile or ~/.bashrc | Interactive shells and their children |
| systemd unit | UMask= directive in the service section | One service and its child processes |
| Application code | umask() system call at runtime | That process from the call onward |
The umask command is a shell builtin, not a separate program, because a child process cannot change the mask of its parent. Running umask without arguments prints the current value, umask -S prints it in symbolic form such as u=rwx,g=rx,o=rx, and umask 027 sets a new value for the current shell.
Since kernel 4.7, the current mask of any process can also be read from the `Umask:` field in `/proc/PID/status`, which is the most reliable way to verify what a running daemon actually uses.
How umask relates to chmod, ACLs and setgid directories
The umask is a creation-time default, whereas chmod changes the mode of an existing object explicitly. The two complement each other: the umask sets the starting point, and chmod or chown adjust individual files later. Neighboring mechanisms in Linux permissions interact with the umask in specific ways.
| Mechanism | When it acts | Interaction with umask |
|---|---|---|
| umask | At file creation | Removes bits from the requested mode |
| chmod | After creation, on demand | Not affected by the umask at all |
| Default ACL | At creation inside a directory | Replaces the umask for that directory |
| Setgid directory | At creation inside a directory | Sets group ownership; umask still sets bits |
| chown | After creation | Changes owners, not permission bits |
The interaction with default ACLs surprises many administrators. When a parent directory carries a default access control list, the kernel ignores the umask for new entries in that directory and derives their permissions from the inherited ACL instead. This makes default ACLs the more precise tool for shared directories.
A setgid directory solves a different problem: it makes new files inherit the directory group rather than the creator’s primary group. Group collaboration typically needs both a setgid bit and a group-friendly umask such as 002, otherwise colleagues share a group but still lack write permission.
Choosing a umask for users and services
The right umask follows from who should read new data by default. A restrictive value protects confidentiality but can break collaboration and web serving, while a permissive value eases sharing at the cost of exposure. The decision table below summarizes common situations.
| Situation | Recommended umask | Reason |
|---|---|---|
| Multi-user workstation | 022 or 027 | Others should not modify user files |
| Distribution with user private groups | 002 | Each user owns a personal group, so group write is safe |
| Team project directory | 002 with setgid | Members must edit each other’s files |
| Service handling secrets | 077 | Keys and tokens must stay owner-only |
| Web content deployment | 022 | The web server user needs read access |
For daemons, the `UMask=` setting in a systemd unit is preferable to editing shell profiles, because services do not read interactive startup files. The systemd default for services is 0022, so a service that writes sensitive output should declare `UMask=0077` explicitly.
Common mistakes and misconceptions
Most umask problems come from wrong assumptions about scope or arithmetic. The following points cover the errors seen most often in administration practice.
- Expecting retroactive effect: changing the umask never alters files that already exist; use chmod for those.
- Subtracting instead of masking: the result is a bitwise operation, so decimal subtraction gives wrong answers for odd values.
- Editing the wrong file: a value set in
~/.bashrcdoes not reach services, cron jobs or graphical sessions started elsewhere. - Forgetting explicit modes: programs that request
0600or call chmod themselves are only narrowed by the umask, never widened. - Ignoring default ACLs: inside a directory with a default ACL, the umask has no effect on new entries.
A further subtlety concerns copy and archive tools. Commands such as cp -p, rsync -p or tar -p preserve source modes, and some extract operations apply the umask only when preservation is off, so the same archive can produce different permissions for different users.
Explained without jargon
Imagine every new file starts life with all doors open. The umask is a list of doors to lock automatically before anyone can walk in. It does not touch rooms that already exist; it only decides how new ones look on day one.
If your umask locks the write door for everyone except you, then others can look at your new files but cannot change them. Locking more doors keeps things private, and locking fewer doors makes sharing easier. The key point is simple: the umask sets safe defaults so you do not have to fix permissions by hand after every file.
A typical use case
A small engineering team keeps shared build scripts in /srv/project on a Linux server. Developers keep complaining that they cannot edit files a colleague created yesterday, even though everyone belongs to the `devteam` group. Inspection shows the files are 644 and owned by each author’s personal group.
The administrator sets the setgid bit on `/srv/project` so new files inherit the devteam group, and changes the login umask from 022 to `002` through `pam_umask`. Existing files are corrected once with chgrp -R devteam and chmod -R g+w. The nightly build service, which runs under systemd, receives UMask=0002 in its unit file.
From then on, every new file appears as 664 and every new directory as 775 with the correct group. Permission complaints stop, and nobody needs to run chmod after saving a file.