chmod 600 (rw-------)
Answer
chmod 600 sets rw-------: the owner can read and write the file, and no one else (other than root) can open it at all. It is the standard mode for files that contain secrets.
chmod 600 = rw-------: owner read and write, everyone else nothing.
| Read 4 | Write 2 | Execute 1 | Digit | |
|---|---|---|---|---|
| Owner (user) | 6 | |||
| Group | 0 | |||
| Others | 0 | |||
| Special | 0 |
6Owner (user): 6 = 4 read + 2 write0Group: 0 = no permissions0Others: 0 = no permissions
On a file
- Owner (user) read it and change it
- Group no access
- Others no access
On a directory
- Owner (user) list the names inside; write without x does nothing useful (names only: without x the files cannot be opened or even stat'ed)
- Group no access
- Others no access
chmod 600 filechmod u=rw,go= filels -l → -rw-------
What to know
6 for the owner is read + write; the two zeros remove every permission for the group and for others. Several programs check for exactly this and refuse to use a secrets file that is more open.
OpenSSH rejects a private key if any group or other bit is set, so 600 and 400 both work, while 640 and 644 do not. PostgreSQL's client ignores a ~/.pgpass file that is group- or world-accessible, and prints a warning asking for 0600.
Where it fits
- SSH private keys (
~/.ssh/id_ed25519,id_rsa) and~/.ssh/config ~/.ssh/authorized_keys(644 is also accepted).envfiles,~/.pgpass,~/.netrcand other credential files- TLS private keys used by a server that reads them as their owner (often root)
Gotchas
- 600 has no execute bit, so it is wrong for a directory: use 700 for
~/.sshitself. - If a service runs as a different user than the file's owner, 600 locks it out. Either change the owner or use 640 with the service's group.
- Copying a key with
cpcreates the new file using your umask (often 644). Check the mode after copying, or useinstall -m 600.
Related explainers
- chmod 400 (r--------)chmod 400 makes a file readable by its owner only, with no write access. Why AWS tells you to chmod 400...
- chmod 700 (rwx------)chmod 700 gives the owner full access and everyone else none. The usual mode for ~/.ssh, ~/.gnupg and...
- chmod 640 (rw-r-----)chmod 640 lets the owner read and write, the group read, and others nothing. The usual mode for secret...
- 600 vs 644600 makes a file readable by its owner only; 644 lets every user read it. Which to use for SSH keys, .env...
- umask 077umask 077 creates files as 600 and directories as 700, so nothing you create is visible to other users....