Permission denied (publickey) — the offer, the refusal, the four causes
Permission denied (publickey) means every offered key was refused — a negotiation verdict, not a password typo. ssh -vvv shows the offers, journalctl -u ssh shows why; one of four causes follows.
Permission denied (publickey) means every key the client offered was refused — a negotiation verdict, not a password typo. ssh -vvv shows which keys were offered; journalctl -u ssh shows why they were refused. Then it's one of four causes.
The log names the verdict, never the cause.
What causes Permission denied (publickey)?
Two lines, one arc: the RSA offer refused at 02:10 — the deploy's death — then the same client, four minutes later, accepted on ed25519.
Oct 18 02:10:03 staging sshd[4421]: Failed publickey for deploy from 203.0.113.7 port 51422 ssh2: RSA SHA256:9T4xQmV…Oct 18 02:14:41 staging sshd[4421]: Accepted publickey for deploy from 203.0.113.7 port 51422 ssh2: ED25519 SHA256:KP7wLn…
| cause | telltale | fix |
|---|---|---|
| Right key exists, wrong one arrives | -vvv offers an identity you don't recognise | ssh-add -l to list, ssh-add -d to drop the stale one |
-i mykey ignored | A config IdentityFile overrides the offer order | Fix or remove the ~/.ssh/config block |
| Key not installed | Server log shows Failed publickey for every offer — authorized_keys: empty, 0 keys | ssh-copy-id user@host |
| Wrong user | Key works for root@host, fails for deploy@host | Key must be in that user's ~/.ssh/authorized_keys |
| Permissions too open | WARNING: UNPROTECTED PRIVATE KEY FILE — the key is skipped, never offered | chmod 700 ~/.ssh; chmod 600 ~/.ssh/* |
| Legacy ssh-rsa key | Server runs OpenSSH 8.8+; old RSA key never accepted | Re-generate as ed25519, or upgrade the key |
ssh -vvv deploy@staging 2>&1 | grep -iE "offering|identity|denied|authentications"— read Offered · still-accepted · denied in order; the first three lines decide which side your problem lives on.journalctl -u ssh -n 50 --no-pager | grep -iE "publickey|denied|accepted"— the server kept its own per-offer tally.- Match the telltale to the table, apply the fix, then prove it:
ssh -o BatchMode=yes deploy@staging 'echo ok'→ ok, no prompt.
the permission gate and the retired tongue
~/.ssh 700 → drwx------ (755 too open) ~/.ssh/id_ed25519 600 → -rw------- (644 and 664 too open) chmod 700 ~/.ssh chmod 600 ~/.ssh/* ssh-keygen -t ed25519 ssh-copy-id deploy@staging ssh -o BatchMode=yes deploy@staging 'echo ok' → ok
WARNING: UNPROTECTED PRIVATE KEY FILE. A key the group or world can read is silently dropped from the offer — the -vvv log shows no offering line at all. OpenSSH 8.8, released 2021-10-01: "the ssh-rsa signature scheme is ... disabled by default" (release notes). An RSA key generated in 2018 isn't broken; its signature format is no longer spoken. rsa-sha2-256 upgrades in place, no re-generation. If password auth is already off and your fix touches authorized_keys, keep the cloud serial console open first — VPS providers all have one that does not depend on sshd.
- tested on: OpenSSH 8.8 → 9.x · Ubuntu · ed25519 + RSA keys · ssh-agent
- diagnosis: ssh -vvv (offers) · journalctl -u ssh (refusals) · BatchMode proof
- 8.8 ssh-rsa default — OpenSSH 8.8 release notes, 2021-10-01
- first published 2026-09-18