“Permissions are too open”: fixing SSH key permissions

SSH is fussy on purpose: if anyone else could read your private key, it refuses to use it. Here are the exact permissions it wants, and the one-line fixes.

The error

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/sam/.ssh/id_ed25519' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.

Mode 0644 means everyone on the machine can read the file. SSH treats a readable private key as a leaked key and skips it, then usually falls back to asking for a password or fails with Permission denied (publickey). It often happens after copying keys from another computer, a USB stick, a zip file or a shared folder, which reset the mode.

The permissions SSH wants

PathModeCommandMeaning
~/.ssh/700chmod 700 ~/.sshOnly you can open the folder
Private keys (id_ed25519, id_rsa)600chmod 600 ~/.ssh/id_ed25519Only you can read or write it
Public keys (*.pub)644chmod 644 ~/.ssh/*.pubPublic by design, fine to share
authorized_keys (on the server)600chmod 600 ~/.ssh/authorized_keysOnly you can change who may log in
config600chmod 600 ~/.ssh/configMust not be writable by others
known_hosts644chmod 644 ~/.ssh/known_hostsNot secret, but keep it yours
Your home folder755 or stricterchmod go-w ~Must not be group- or world-writable

Ownership matters as much as mode: chown -R $USER: ~/.ssh fixes keys that were copied in as root. On the server side, sshd silently ignores authorized_keys when the file, the .ssh folder or the home folder is writable by anyone else (the StrictModes setting), which is the usual cause of “my key is in authorized_keys but it still asks for a password”.

New to the three-digit numbers? chmod 755 and 644 explained breaks them down, and the number base converter shows each digit as read, write and execute bits.

Fixing it on Windows

Windows' built-in OpenSSH does the same check using file permissions instead of chmod. In PowerShell:

icacls $env:USERPROFILE\.ssh\id_ed25519 /inheritance:r
icacls $env:USERPROFILE\.ssh\id_ed25519 /grant:r "$($env:USERNAME):(R)"

The first line stops the file inheriting access from its folder, the second gives read access to you alone. Keys kept in WSL should live inside the Linux file system (~/.ssh in WSL), not under /mnt/c, where chmod does not stick by default.

Making a new key the right way

ssh-keygen -t ed25519 -C "laptop-2026"

ssh-keygen creates the files with the right modes already. Ed25519 keys are short, fast and supported everywhere modern; use -t rsa -b 4096 only for very old servers. Add a passphrase and let ssh-agent remember it, so a stolen laptop doesn't mean a stolen login. The comment after -C is just a label; it is visible to anyone who sees the public key, so keep it neutral.

Other key errors, decoded

Getting Permission denied (publickey) instead? Follow the publickey guide.

Comparing fingerprints? ssh-keygen -lf key.pub prints the SHA256 fingerprint SSH shows on first connect. Not sure what a blob of text is? Paste a public key (never a private one) into What is this?.

Questions

What permissions should an SSH private key have?

600 (read and write for the owner only) or 400 (read-only for the owner). Anything that lets the group or others read it makes SSH ignore the key.

What permissions should the .ssh folder have?

700, so only the owner can list or enter it. authorized_keys and config inside it should be 600.

Why does SSH still ask for a password after I added my key?

Usually the server is ignoring authorized_keys because the file, the .ssh folder or the home folder is writable by someone else, or the key is owned by the wrong user. Fix the permissions and ownership, then try ssh -v to see what happens.

Is it safe to share my .pub file?

Yes. The public key is meant to be copied to servers and services. Only the file without .pub must stay private.

Published .

Try it

Related guides

Newest guides