umask 077
Answer
With umask 077, new files are created 600 (rw-------) and new directories 700 (rwx------). Nothing you create is readable by your group or by other users unless you change it explicitly.
What umask 077 gives
- New files
600rw-------- New directories
700rwx------umask -Su=rwx,g=,o=
What to know
077 is a sensible umask for scripts that write secrets, backups or key material: set umask 077 at the top of the script so every file it creates starts private, with no window where it is briefly readable.
Some hardening guides recommend 027 instead (files 640, directories 750), which keeps the group able to read.
Gotchas
- Files that other users or services must read (web content, shared configs) end up unreadable, which shows up later as 403 errors or "Permission denied" in a different program.
- With umask 077,
chmod +x filegives only the owner execute (644 becomes 744), because chmod with no who-letter is filtered by the umask. - Installing software under umask 077 as root can leave files in /usr/local or /opt unreadable for normal users.
Related explainers
- umask 022umask 022 means new files are created 644 (rw-r--r--) and new directories 755 (rwxr-xr-x). How the umask...
- umask 002umask 002 creates files as 664 and directories as 775, so your group can edit what you create. When to use...
- chmod 600 (rw-------)chmod 600 makes a file readable and writable by its owner only. The right mode for SSH private keys, .env...
- chmod 700 (rwx------)chmod 700 gives the owner full access and everyone else none. The usual mode for ~/.ssh, ~/.gnupg and...