chmod 600: private files for SSH keys, .env and other secrets

Open this example in the tool

Try it in the tool

Chmod Calculator

Translate 755 ↔ rwxr-xr-x ↔ u=rwx,g=rx,o=rx instantly.

chmod 600 gives the owner read and write and nobody else anything: rw-------. It is the standard mode for secrets in files.

Octal      600
Symbolic   rw-------   (ls -l: -rw-------)
Command    chmod 600 file

  owner   6  read  write
  group   0
  others  0

What needs 600

  • SSH private keys: ~/.ssh/id_ed25519, id_rsa. OpenSSH refuses a key that other users can read, with this message: WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions 0644 for 'id_ed25519' are too open.
  • ~/.ssh/config and authorized_keys: OpenSSH insists that they cannot be written by others, and 600 is the safe setting.
  • .env files, API tokens, credentials files (~/.aws/credentials, ~/.netrc).
  • PostgreSQL’s ~/.pgpass, which the client ignores unless the permissions are u=rw (0600): WARNING: password file has group or world access.
  • Private keys for TLS on servers (often 600 or 640, readable by the service’s group).

The fix for “permissions are too open”

chmod 600 ~/.ssh/id_ed25519
chmod 700 ~/.ssh
ls -l ~/.ssh

The folder matters too. If ~/.ssh is writable by others, they could replace the keys inside, so it must be 700. A key that came from a download folder, a zip file, or a Windows drive often arrives as 644 or 755, and a drive formatted as FAT or NTFS cannot hold Unix permissions at all, so copy the key to your home folder first.

Check the owner as well as the mode

The mode only means something relative to the owner. A file that is 600 but owned by root is unreadable by you. A key you copied with sudo has the same problem:

ls -l id_ed25519          # who is the owner?
sudo chown "$USER" id_ed25519

600 or 400?

Use 400 for a key you should never edit; AWS tells you to run chmod 400 key.pem after you download it. Use 600 when the file changes, such as a .env or a config that you edit. If a group must read it (a service key shared by a process group), use 640 with the right group, never 644.

Two limits

  • 600 does not hide a file from root, and does not encrypt it. For real secrets keep them out of the repository, and out of images and backups that others can read.
  • If a secret file was ever 644, assume that it was readable: rotate the secret if the machine was shared.

The chmod calculator turns rw------- back into 600 and the reverse. Related: 644 for public files and 755 for folders; a “Permission denied” from a web server is explained on 403 Forbidden.

Frequently asked questions

What does chmod 600 mean?

Only the owner can read and write the file (rw-------). The group and everyone else have no access at all, not even to read.

Why does ssh say 'UNPROTECTED PRIVATE KEY FILE'?

The key file is readable by other users (for example 644), so ssh treats the key as possibly stolen and refuses it. Run chmod 600 on the key; the folder ~/.ssh should be 700.

What is the difference between 600 and 400?

Both hide the file from others. 600 lets the owner edit it, 400 makes it read-only even for the owner, which protects against accidental changes. Cloud providers often tell you to use 400 for downloaded .pem keys.

Does chmod 600 stop root from reading the file?

No. The superuser ignores permission bits. 600 protects against other ordinary users and services, not against an administrator or a process running as root.

More in this reference