What the message looks like
admin@203.0.113.10: Permission denied (publickey).Common causes
- Wrong username, e.g. root instead of ubuntu or admin.
- Public key missing from
~/.ssh/authorized_keys, or wrapped across lines there. - Permissions too open: home group-writable,
.sshnot 700 orauthorized_keysnot 600 (StrictModes). - Old RSA key with SHA-1 signature: newer OpenSSH versions reject
ssh-rsa. - The agent offers too many keys and the server stops after
MaxAuthTries.
Check
- See in the client which keys are offered and rejected
ssh -vvv admin@203.0.113.10 2>&1 | grep -E 'Offering|Server accepts|Authentications that can continue|no mutual' - Check the server log for the login
- Check permissions on home, .ssh and authorized_keys
ls -ld ~admin ~admin/.ssh ~admin/.ssh/authorized_keys - Show effective sshd settings
sshd -T | grep -E 'pubkeyauthentication|authorizedkeysfile|allowusers|pubkeyacceptedalgorithms'
Fix
- Connect with the right key:
ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes admin@host. - Install the key properly:
ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@hostor via the hoster's console. - Set permissions:
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keysand check ownership. - Replace old RSA keys with Ed25519 instead of re-enabling
ssh-rsa. - With SELinux:
restorecon -Rv ~/.ssh.
Typical scenario
An admin sets up a new Ubuntu server, places his public key in ~/.ssh/authorized_keys and still gets 'Permission denied (publickey)'. On the server the home directory accidentally belongs to the group and is group-writable because it was copied by a script. With StrictModes, which is on by default, sshd then ignores the key file. Check journalctl -u ssh for 'Authentication refused: bad ownership or modes'.
FAQ
How do I get in if I am locked out?
Through the hoster's web or rescue console. Add the key to authorized_keys there and check permissions – do not enable PasswordAuthentication permanently.
Why does one key work and another does not?
The server only accepts keys whose public part is in authorized_keys and whose type is allowed. ssh -vvv shows which key was offered.
Which permissions does sshd expect?
The home directory must not be writable by group or others, ~/.ssh should be 700 and authorized_keys 600, all owned by the user. If they differ, sshd with StrictModes on discards the file and logs the reason.
What does 'Too many authentication failures' mean instead of the message above?
The client offers every key from the ssh-agent one after another and the server gives up after MaxAuthTries attempts before the right one is reached. With -o IdentitiesOnly=yes -i ~/.ssh/key you offer only the key you want.
Why are old RSA keys suddenly refused?
Newer OpenSSH versions disable the SHA-1 signature scheme ssh-rsa by default. Older clients offer only that. The key file itself is fine; the client needs an update, or a more modern key pair such as Ed25519.