Knowledge

SSH Permission denied (publickey)

#Hosting

This SSH error means the server rejected every key your client offered. Usually the right key is not being sent, or the file permissions on the server are wrong.

Published by Mark van Eijk on June 23, 2026 · 1 minute read

  1. About the error
  2. Why do I see this error
  3. Solution
  4. Diagnose first
  5. Make sure your key is on the server
  6. Offer only the right key
  7. Fix permissions on the server

About the error

Connecting over SSH fails with:

Permission denied (publickey).

The server only accepts public-key authentication, and none of the keys your client presented matched an entry in the account's authorized_keys. A related variant, Too many authentication failures, means your client offered so many wrong keys that the server cut you off before reaching the right one.

Why do I see this error

  • Your public key isn't in the server's ~/.ssh/authorized_keys.
  • The client is offering the wrong key, or every key in your agent.
  • File permissions on the server's .ssh directory or authorized_keys are too open, so sshd ignores them.
  • You're connecting as the wrong user.

Solution

Diagnose first

Verbose output shows exactly which keys are offered and how the server responds:

ssh -vvv user@your-server

Make sure your key is on the server

The easiest way to install your public key is ssh-copy-id:

ssh-copy-id user@your-server

Or append it manually to ~/.ssh/authorized_keys on the server.

Offer only the right key

If you have many keys, the agent offers them all and can trip "Too many authentication failures". Force a single key and ignore the agent:

ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 user@your-server

Make it permanent in ~/.ssh/config:

Host your-server
    HostName your-server.example.com
    User deployer
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

Fix permissions on the server

sshd refuses keys if the files are world-writable. The .ssh directory must be 700 and authorized_keys must be 600, both owned by the account's user:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R $USER:$USER ~/.ssh

After fixing this, reconnect and the key should be accepted.

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

Related articles

How to get top processes with highest memory usage

This SSH error means the server rejected every key your client offered. Usually the right key is not being sent, or the file permissions on the server are wrong.

Read more →

How to get top processes with highest CPU usage

This SSH error means the server rejected every key your client offered. Usually the right key is not being sent, or the file permissions on the server are wrong.

Read more →