chmod 600 (rw-------)
Read and write for the owner, nothing for anyone else. This is the mode for private keys, password files and anything else that holds a secret.
This tool runs in your browser. We never send what you type or paste to a server.
What chmod 600 sets
| Who | Digit | Read | Write | Execute | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 6 | yes | yes | no | rw- |
| Group (g) | 0 | no | no | no | --- |
| Others (o) | 0 | no | no | no | --- |
chmod 600 file # numeric
chmod u=rw,go= file # the same, in symbolic form
ls -l shows this mode as -rw------- on a file and drw------- on a directory. On a file, execute means it can be run as a program. On a directory, read lists the names inside, write creates, renames and deletes entries, and execute (search) is what lets you enter it and reach the files inside.
Files that should be 600
- SSH private keys (
~/.ssh/id_ed25519,~/.ssh/id_rsa). ssh ignores a private key that anyone else can access. ~/.ssh/authorized_keysand~/.ssh/config. The OpenSSH manual recommends read and write for the user and no access for others.- Credential files.
.envfiles, API tokens, database dumps. Some programs enforce it: PostgreSQL ignores~/.pgpassif the group or others have any access to it.
The catch is that the program reading the secret must run as the file's owner. If your web application runs as a different user from the one that deployed the .env file, 600 locks the application out. Do not answer that with 644: give the file to a group the service is in and use 640, or make the service account the owner.
The ssh "UNPROTECTED PRIVATE KEY FILE" warning
If a key you own has any group or others permission bit set, ssh prints this warning, reports something like Permissions 0644 for 'id_ed25519' are too open, and skips the key. The connection then falls back to another key or a password, or fails. Fix the file, and the directory while you are there:
chmod 600 ~/.ssh/id_ed25519
chmod 700 ~/.ssh
The server has a separate check. With StrictModes on, which is the default, sshd will not use authorized_keys if that file, ~/.ssh or your home directory is writable by the group or by others. Key logins are then refused even though the key itself is correct. On the server:
chmod go-w ~ ~/.ssh ~/.ssh/authorized_keys
600 on a directory
Wrong: a directory needs the execute bit before even its owner can enter it. This is how chmod -R 600 ~/.ssh breaks SSH completely. The private mode for a directory is 700. To strip group and others from a whole tree without touching the owner's bits:
chmod -R go= ~/private
Creating a file as 600 from the start
A file created normally starts out readable by everyone (644 under the usual umask), so a secret is exposed for the moment between creating it and running chmod. Close that gap by setting the umask first:
(umask 077; touch .env) # subshell: the umask change does not leak out
umask 077 # or for the rest of this shell: files 600, directories 700
stat -c '%a %n' .env # GNU/Linux
stat -f '%Lp %N' .env # macOS and BSD
Temporary files made with mktemp are created readable and writable by you alone.
600 compared with its neighbours
| Mode | Symbolic | Difference from 600 |
|---|---|---|
| 400 | r-------- | The owner cannot write either: for keys that never change |
| 640 | rw-r----- | One group can read: for a secret a service account must load |
| 644 | rw-r--r-- | Everyone can read: for anything that is not a secret |
| 700 | rwx------ | Adds execute: the private mode for directories and scripts |
Questions
How do I fix "WARNING: UNPROTECTED PRIVATE KEY FILE!" from ssh?
Run chmod 600 on the private key file named in the message (chmod 400 also works). ssh refuses to use a private key that has any permission set for the group or for others. If the message keeps appearing, the key is probably on a file system that does not store Unix permissions, such as a Windows or FAT drive; copy it into your home directory and set the mode there.
Should authorized_keys be 600 or 644?
The OpenSSH manual recommends 600. sshd itself only refuses the file when it, the .ssh directory or the home directory is writable by the group or by others, so 644 still works, but there is no reason to let other users read the list of keys.
Does chmod 600 hide a file from root?
No. Root can read and write any file regardless of its mode, and so can anyone who is able to run commands as the owner. 600 protects a file from the other ordinary accounts on the machine. If administrators must not be able to read it, the file needs encrypting.