How chmod 600 (rw-------) Secures SSH Private Keys & Fixes OpenSSH Errors
Octal permission 600 (symbolic representation -rw-------) restricts a file exclusively to its owner: Read (4) + Write (2) = 6 for the owner, and 0 (---) for both group members and all other local users. Zero group or world access is enforced at the kernel VFS layer for every non-root process.
If you encounter the OpenSSH error WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions 0644 for ~/.ssh/id_ed25519 are too open, running chmod 600 ~/.ssh/id_ed25519 (or chmod 600 ~/.ssh/id_rsa) immediately resolves the rejection. OpenSSH checks st_mode via stat(2) before loading any identity file or ~/.ssh/authorized_keys file and aborts if any group or world bits are non-zero.
- SSH Private Keys (~/.ssh/id_ed25519, ~/.ssh/id_rsa, .pem): Required by ssh and scp clients to prevent other local users on multi-tenant hosts from reading private cryptographic material.
- Production .env, TLS Private Keys & ~/.pgpass: PostgreSQL libpq refuses to read ~/.pgpass unless its permissions are exactly chmod 0600.
Complete ~/.ssh Directory Hardening Checklist (700, 600 & 644)
Securing an individual key file with chmod 600 is only half of the OpenSSH StrictModes verification pass. During public-key authentication, sshd also inspects the parent ~/.ssh directory and the user home directory (~): if either directory is writable by group or world users, an unprivileged account could unlink and replace your ~/.ssh/authorized_keys file even when the file itself is mode 600.
For automated CI/CD runners, Kubernetes Secret volume mounts (defaultMode: 0600), and cloud bastion hosts, combine chmod 700 on ~/.ssh with chmod 600 on private keys and chmod 400 on immutable cloud .pem keypairs.
- Parent ~/.ssh Directory (chmod 700 / drwx------): Grants owner rwx traversal while blocking every other local user from listing or modifying files inside ~/.ssh.
- chmod 600 vs chmod 400 for AWS EC2 .pem Keys: chmod 600 allows the owner to rotate or overwrite the key file, whereas chmod 400 (r--------) makes the key read-only even to its owner to prevent accidental edits.
Practical Real-World Use Cases
Security-critical daemons and cloud deployment pipelines enforce mode 0600 before loading credential files from disk:
- Fixing OpenSSH & Bastion Host Key Rejections: Run chmod 600 ~/.ssh/id_ed25519 and chmod 600 ~/.ssh/authorized_keys after copying keys onto a new VM or macOS workstation so ssh stops rejecting 0644 identity files.
- PostgreSQL ~/.pgpass, Netrc & WireGuard Private Keys: Satisfy mandatory libpq, curl --netrc, and wg-quick permission checks on ~/.pgpass, ~/.netrc, and /etc/wireguard/wg0.conf.
- Production .env Secrets & Kubernetes Secret Mounts: Set defaultMode: 0600 (decimal 384 in YAML) on Kubernetes Secret volumes and host .env files so co-located processes cannot read database or Stripe API keys.
Frequently Asked Questions
Why does SSH fail with "Permissions 0644 are too open" and how does chmod 600 fix it?
OpenSSH refuses to use private keys if any group or public permission bits are enabled. Running chmod 600 ~/.ssh/id_ed25519 removes all group and public access (setting rw-------), satisfying the strict OpenSSH security check.
What permissions should the ~/.ssh directory and authorized_keys have?
Set the ~/.ssh directory itself to chmod 700 (drwx------), private keys and ~/.ssh/authorized_keys to chmod 600 (-rw-------), and public keys (*.pub) to chmod 644 (-rw-r--r--).