SSH just refused your key with a wall of @ symbols and WARNING: UNPROTECTED PRIVATE KEY FILE!. On Linux or macOS, fix it by restricting the private key named in the error to its owner with chmod 600. On Windows, inspect and restrict its NTFS access list. If the key loads but the server answers Permission denied (publickey), jump to the publickey checklist further down. If the warning is about the server instead (REMOTE HOST IDENTIFICATION HAS CHANGED), see Host key verification failed.
chmod 600 ~/.ssh/id_ed25519If ownership and the filesystem permission model are correct, this clears the usual Unix mode error. On Windows, removing inheritance does not remove unrelated explicit access entries; complete the ACL checks below. The rest of this page is the why, the full set of permissions SSH checks, and the ownership trap that chmod alone does not fix.
Pick your OS. The commands below switch to the right form (chmod on Linux/macOS, icacls on Windows).
What the error actually says
Run anything that loads the key and SSH stops you cold:

The number in the message (0644, 0640, 0444, whatever yours is) is the current mode. Anything that grants group or other a single bit on a private key trips the check. SSH then refuses to use the key and falls back to the next auth method, which is usually why you also see Permission denied (publickey).
Why SSH is this strict
A private key is a secret. If any other account on the machine can read the file, they can copy your key and impersonate you on every server that trusts it. So OpenSSH refuses to load a private key whose permissions let anyone but the owner read it. On the server side the same rule is enforced by StrictModes, which is on by default in sshd: a world-writable ~/.ssh or authorized_keys gets silently ignored, and you are left wondering why key auth "stopped working."
This almost always shows up after you copied keys from another machine (a backup, a new laptop, a Docker bind mount, a cloud sync folder) and the loose permissions came along for the ride. Freshly generated keys already have the right modes; see how to create an SSH key for that flow.
The full set of permissions SSH expects
These are common restrictive Unix permissions. Apply them only to files that exist and belong to this account; authorized_keys is a server-side authorization file, not the client private key.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/configHere is what each file should look like on Linux and macOS:
| Path | Mode | Meaning |
|---|---|---|
~/.ssh | 700 | only you can enter the directory |
~/.ssh/id_ed25519 (private) | 600 | only you can read or write the key |
~/.ssh/id_ed25519.pub (public) | 644 | public, safe for anyone to read |
~/.ssh/authorized_keys | 600 | the keys allowed to log in as you |
~/.ssh/config | 600 | may contain hostnames and key paths |
A correct ~/.ssh looks like this:

chmod is not enough if the owner is wrong
chmod sets the mode, but SSH also checks who owns the file. If the key is owned by root (the classic result of running sudo ssh-keygen), no amount of chmod as your normal user will help, because you cannot even change a file you do not own. Fix the owner first:
sudo chown "$(id -u):$(id -g)" ~/.ssh ~/.ssh/id_ed25519 && chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_ed25519One more owner-level trap: your home directory must not be group- or world-writable either. If chmod 700 ~/.ssh did not help, check ~ itself with ls -ld ~ and tighten it (chmod g-w,o-w ~). sshd walks the whole path and refuses keys sitting under a loosely-permissioned home.
Windows: it is ACLs, not chmod
Windows OpenSSH checks NTFS access-control entries. Inspect the specific private key first in PowerShell:
$key = "$env:USERPROFILE\.ssh\id_ed25519"
(Get-Acl -LiteralPath $key).Owner
icacls $keyConfirm that this is your key and that the owner is the intended account. Then remove inherited entries and grant your current Windows identity read access:
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
icacls $key /inheritance:r /grant:r "${identity}:R"
icacls $keyInspect the final output. /grant:r replaces grants for the named identity; it does not erase every other explicit user or group entry. Remove unexpected access through Properties → Security → Advanced, reviewing each entry rather than recursively resetting the whole .ssh folder. Preserve required system access according to your managed environment's policy. Microsoft documents the icacls flags.
If the owner is another account, correct that deliberately using an account authorized to change ownership, then recheck the ACL. A WSL key on /mnt/c may also have Windows filesystem semantics; a key in WSL's own home filesystem is easier to manage with Unix modes.
Fix Permission denied (publickey)
Permission denied (publickey) means the server offered only key authentication and rejected every key you presented. Loose permissions are one cause (a key SSH refuses to load is never offered), but not the only one. Read it this way: either you did not send a key the server trusts, or the server cannot use the key you sent. Work the list in order.
First, see what SSH is actually doing
ssh -v user@serverThe verbose log shows which keys are offered (Offering public key:) and how the server responds. If you see your key offered and then Authentications that can continue: publickey again, the server does not have your public key. If your key is never offered, the problem is local.
The checklist
1. Is the public key on the server? The server only trusts keys listed in ~/.ssh/authorized_keys for that user. Install it with ssh-copy-id or by hand. This is the single most common cause.
2. Are you offering the right key? If you have several keys, SSH may try the wrong ones and give up once it exhausts the server's MaxAuthTries. Point at the exact key:
ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes user@serverIf that works (and it fails without -i), set IdentityFile and IdentitiesOnly yes for that host in ~/.ssh/config so you do not type it every time.
3. Is the key loaded in the agent? If the key has a passphrase and is not in the agent, some setups will not offer it:
ssh-add -l # list loaded keys
ssh-add ~/.ssh/id_ed255194. Server-side permissions. sshd silently refuses ~/.ssh or authorized_keys if they are too permissive. On the server, as the user you log in as: chmod 700 ~/.ssh, chmod 600 ~/.ssh/authorized_keys, and make sure the home directory is not group-writable. This is the same StrictModes rule described above, and it produces this exact error.
5. Right user. ssh ubuntu@host and ssh root@host look at different authorized_keys files. The key has to be in the file for the user you are logging in as. Cloud images each have their own default user (see SSH into EC2).
6. Server config forbids it. As a last resort, the server may set PubkeyAuthentication no or restrict users via AllowUsers/AllowGroups in sshd_config. You need existing access to inspect or change that.
90% of the time the fix is one of: install the public key on the server (step 1), or tighten the server-side permissions (step 4). Run ssh -v, find which side is failing, and you will know which. If you only see it against GitHub, the Git-specific version of this error has its own walkthrough.
Fix "Host key verification failed"
The other SSH wall comes from the opposite side. Instead of the server rejecting your key, your client rejects the server's: a block of @ symbols, WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!, and then Host key verification failed. The server is presenting a different host key than the one SSH remembered in ~/.ssh/known_hosts. If you know why it changed, the fix is one command. If you do not, stop and find out first, because this is exactly what a machine-in-the-middle attack looks like.
When a changed host key is benign, and when it is not
The host key legitimately changes when:
- The server was rebuilt, reinstalled, or reprovisioned.
- A new VM got the same IP address as an old one (very common with cloud and DHCP).
- You are connecting through a load balancer or a port-forward to a different backend.
If nothing changed on the server and you did not expect a new key, treat it as a real warning. Do not blindly delete the entry. Verify the new fingerprint out of band (from the provider console, the server's /etc/ssh/ssh_host_ed25519_key.pub, or a colleague) before trusting it. To compare, print the fingerprint the server is presenting:
ssh-keygen -lf <(ssh-keyscan server.example.com 2>/dev/null)If it matches the console value, accept it. If it does not, you have a real problem, not a stale entry.
Remove the stale known_hosts entry
Once you are sure the new key is legitimate, drop the old line from known_hosts:
ssh-keygen -R server.example.comThat removes every key stored for that host. The next connection shows the normal "authenticity of host ... can't be established, continue?" prompt; type yes and the new key is saved. For a host on a non-standard port, include it: ssh-keygen -R '[server.example.com]:2222'. You can also open ~/.ssh/known_hosts and delete the offending line by hand; the warning names the exact line (Offending key in /home/you/.ssh/known_hosts:14).
If the warning persists after that, you probably have a second entry keyed by the IP address (or a hostname,ip line). Clear both forms:
ssh-keygen -R server.example.com
ssh-keygen -R 203.0.113.10The same error on git clone, pull, and push
Git talks to GitHub or GitLab over SSH, so a git pull that fails with Host key verification failed is the identical problem with the identical fix: ssh-keygen -R github.com, then let the next connection re-trust the host. For GitHub specifically, verify the new key against GitHub's published SSH key fingerprints page before accepting it, since a changed GitHub host key is far more likely an interception than a rebuild.
A safer default for ephemeral hosts
If you spin up and tear down servers constantly (CI, test VMs) on reused IPs, the warning is noise. Rather than disabling host checking entirely (StrictHostKeyChecking no, which removes the protection), use accept-new, which trusts new hosts but still fails if a known key changes:
# ~/.ssh/config
Host *.test.example.com
StrictHostKeyChecking accept-new
FAQ
It means your private key file can be read by users other than you (mode 0644 grants read to group and other). SSH treats a readable private key as compromised and refuses to use it. Run chmod 600 ~/.ssh/id_ed25519 so only you can read it, and the warning disappears.
Almost always because the key (or ~/.ssh) was copied somewhere with looser permissions: a new laptop, a restored backup, a Docker bind mount, or a cloud-synced folder. The bytes are fine; the mode came across too open. Re-tighten with the commands above. On the server side, the same thing happens if ~/.ssh or authorized_keys became group-writable, because sshd StrictModes then ignores them.
Check ownership, not just the mode. If the file is owned by root (common after sudo ssh-keygen), fix it with sudo chown $USER ~/.ssh/id_ed25519 first. Also confirm your home directory is not group- or world-writable: ls -ld ~, then chmod g-w,o-w ~ if needed.
Directory ~/.ssh = 700, private keys = 600, public keys (.pub) = 644, authorized_keys = 600, and config = 600. The directory and all private material should be owned by you, and your home directory must not be writable by group or other.
Inspect the key owner and ACL, remove inherited access if appropriate, grant the intended account access, and check for remaining explicit grants. The PowerShell walkthrough above explains why inheritance removal alone may not be enough.
The server has disabled password authentication (PasswordAuthentication no) and only accepts keys. Permission denied (publickey) is telling you the only allowed method is a key, and none of yours worked. Install your public key on the server, or regain access another way to re-enable passwords.
The server does not have that public key in the target user's authorized_keys, or the server-side permissions on ~/.ssh / authorized_keys are too loose and sshd is ignoring the file. Re-install the key and run chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys on the server.
Only if you know why the host key changed (a rebuild, a reused IP, a reinstall). If the change is unexpected, the warning is doing its job: someone could be intercepting the connection. Verify the new fingerprint against the provider console before removing the entry.
No. no disables the protection that catches interception. For throwaway hosts use accept-new instead: it auto-accepts first-time keys but still refuses a connection whose stored key has changed.
See also
- How to Create an SSH Key in 2026: generate a key with the right permissions from the start, and why you should never
sudo ssh-keygen. - SSH Cheat Sheet: the rest of the SSH surface, including the
~/.ssh/configandssh-copy-idthis error often interrupts. - How to find files by owner, group, or permission: audit a whole tree for the loose modes that cause this.
- ssh_scan: scan the server side, not just your key files.
- Fix "Host key verification failed": the other SSH wall, on the server-identity side, covered above.
Sources
Authoritative references this article was fact-checked against.
- ssh(1) manual page (OpenBSD)man.openbsd.org
- sshd(8) manual page (OpenBSD, StrictModes)man.openbsd.org
- OpenSSH key management on Windows (Microsoft Learn)learn.microsoft.com
- ssh-keygen(1) manual page (OpenBSD)man.openbsd.org





