One Error Message, At Least Six Different Causes
Permission denied (publickey) is one of the most-searched SSH errors that exists, and the frustrating part is that the message itself gives you almost no information about which of several unrelated problems you're actually facing. A permissions issue, a wrong key, an unloaded agent, and a server-side config restriction all produce the exact same line. Here's how to tell them apart and fix each one.
user@host: Permission denied (publickey).
Step Zero: Always Start With Verbose Mode
Before guessing, get more information:
ssh -v user@host
This prints every key ssh offers and the server's response to each — it's the fastest way to know whether the problem is "no key was offered," "the right key was offered and rejected," or "ssh gave up before trying the right key at all." Everything below assumes you've looked at this output.
Cause 1: Server-Side Directory/File Permissions (StrictModes)
# in the server's auth log, not on your client:
Authentication refused: bad ownership or modes for directory /home/user
What it means: OpenSSH's StrictModes setting (on by default) refuses public-key authentication if the permissions on your home directory, ~/.ssh, or ~/.ssh/authorized_keys are too permissive — specifically, writable by anyone other than the owner. This is one of the most commonly missed causes, because people check authorized_keys itself and stop there, missing that the directories above it matter just as much.
Fix — on the server:
chmod 700 ~
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Cause 2: The Public Key Isn't Actually in authorized_keys
The most direct cause: the key genuinely isn't there, or was corrupted in transit — a common one is copy-pasting a public key and accidentally splitting it across two lines, or missing the trailing part of the key entirely.
Check on the server:
cat ~/.ssh/authorized_keys
Confirm it's a single unbroken line starting with ssh-ed25519 or ssh-rsa, matching your local public key file (~/.ssh/id_ed25519.pub or similar) exactly.
Cause 3: SSH Is Offering the Wrong Key
debug1: Offering public key: /home/user/.ssh/id_rsa_old RSA SHA256:...
debug1: Authentications that can continue: publickey
...
Received disconnect from host: Too many authentication failures
What it means: if you have multiple keys in ~/.ssh or loaded in ssh-agent, ssh tries them in order until one works — but the server's MaxAuthTries (commonly 6) caps how many attempts it'll accept per connection. With several keys loaded, ssh can burn through that limit on the wrong ones before ever offering the correct key, producing "Too many authentication failures" instead of a normal denial.
Fix — force the specific key:
ssh -i ~/.ssh/id_ed25519 user@host
Or make it permanent for that host in ~/.ssh/config:
Host myserver
HostName host.example.com
User user
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
IdentitiesOnly yes is the important part — it stops ssh from also offering every other key it can find.