How to Diagnose SSH Permission Denied (publickey)
SSH 'Permission denied (publickey)' means the server rejected every key offered. A throwaway SSH server shows what ssh -v reveals for wrong and right keys.
Permission denied (publickey) means the SSH server only accepts key authentication and none of the keys your client offered is in the server’s authorized_keys for that user, or the client offered no key at all. Run the connection again with ssh -v: the Offering public key lines show exactly which keys were tried, and a missing Server accepts key line confirms the server rejected them.
What ssh -v shows
We set up a disposable SSH server on localhost that trusts exactly one key, then connected three ways.
Wrong key:
debug1: Authenticating to 127.0.0.1:2222 as 'demo'
debug1: Authentications that can continue: publickey
debug1: Offering public key: ~/lab/wrong_key ED25519 SHA256:dZNQR+1JHtZyCvVzbUNuo0XEWaotFOEw21V0yVHj6rA explicit
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
demo@127.0.0.1: Permission denied (publickey).
Authorized key:
debug1: Offering public key: ~/lab/authorized_key ED25519 SHA256:+BwsG77QgFOeadV0NHpDgm9nw2yUPbnsSaWLQ0wiXNE explicit
debug1: Server accepts key: ~/lab/authorized_key ED25519 SHA256:+BwsG77QgFOeadV0NHpDgm9nw2yUPbnsSaWLQ0wiXNE explicit
Authenticated to 127.0.0.1 ([127.0.0.1]:2222) using "publickey".
No key specified (with IdentitiesOnly=yes, so ssh only tries its default key paths, none of which held a usable key in the lab):
debug1: Will attempt key: /Users/demo/.ssh/id_rsa
debug1: Will attempt key: /Users/demo/.ssh/id_ed25519
…
debug1: No more authentication methods to try.
demo@127.0.0.1: Permission denied (publickey).
Three things to read in the output: which user you are logging in as (as 'demo'), which key fingerprints were offered, and whether any line says Server accepts key. Compare the offered fingerprint with the one registered on the server using ssh-keygen -lf key.pub.
The server side was less talkative. At the default log level, sshd recorded only Connection closed by authenticating user demo 127.0.0.1 port 56150 [preauth] for the rejected attempt, and Accepted publickey for demo … for the successful one. Client-side -v is usually the faster route.
Find the cause
Is the user in 'Authenticating to … as' the right account?
For GitHub/GitLab it must be 'git'; for a server, your account there.
- No →
Use the correct username.
ssh user@host or set User in ~/.ssh/config. Git hosting services always use the account 'git'; your identity comes from the key.
ssh -T git@github.com - Yes →
Is there an 'Offering public key' line for the key you expect?
- No key offered at all →
The client has no key to offer.
Create one, or point ssh at an existing one with -i or IdentityFile in ~/.ssh/config. If you use an agent, check ssh-add -l lists it.
ssh-keygen -t ed25519 -C "you@example.com" ssh -i ~/.ssh/id_ed25519 user@host - A different key is offered →
Make ssh offer the right key.
Add a Host block with IdentityFile and IdentitiesOnly yes. With many keys loaded in an agent, servers may disconnect after too many attempts before reaching the right one.
- Yes, the right key →
Is that key's public half in the server's ~/.ssh/authorized_keys for this user?
Check the fingerprint with ssh-keygen -lf, on both sides.
- No / not sure →
Install the public key on the server.
Append the .pub file's single line to ~/.ssh/authorized_keys of the target user (ssh-copy-id does this), or add it in the Git host's SSH keys settings.
- Yes →
Check server-side permissions and settings.
With StrictModes (the default), sshd ignores authorized_keys if the home directory, ~/.ssh or the file is writable by others. Use chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys. Also check AuthorizedKeysFile and that the key type is allowed (PubkeyAcceptedAlgorithms).
- No / not sure →
- No key offered at all →
Common fixes
- Wrong user:
git@github.com, notyourname@github.com; on servers, the account the key was installed for. - Wrong key offered: add a
Hostblock to~/.ssh/configwithIdentityFileandIdentitiesOnly yes. - Key not installed: add the
.publine to~/.ssh/authorized_keyson the server, or to your Git host’s SSH key settings. - Permissions:
chmod 700 ~/.sshandchmod 600 ~/.ssh/authorized_keyson the server; private keys on the client should be readable only by you (chmod 600). - Old key types: recent OpenSSH releases disable
ssh-rsasignatures with SHA-1 by default; generate aned25519key if an old RSA key is refused.
Never fix this by copying a private key to the server; only the .pub half belongs there. If the connection fails before authentication, with Connection refused, the problem is the server or port, not the key; the connection refused guide covers that.
Sources
- ssh(1) — OpenBSD manual pages
- sshd(8): AUTHORIZED_KEYS FILE FORMAT — OpenBSD manual pages
- ssh-keygen(1) — OpenBSD manual pages
How we made this
Reproduced in a local lab. We ran a throwaway, user-level OpenSSH server on 127.0.0.1:2222 (password login off, one authorized ed25519 key) and connected with ssh -v using a key that was not authorized, the authorized key, and no explicit key. Output is quoted verbatim except that the local account name is replaced with 'demo' and the lab directory with ~/lab. The test keys were deleted afterwards.
Performed by Claude, an AI assistant working in the BinConvert repository (macOS, OpenSSH_10.3p1), November 16, 2026.
This article was drafted with AI assistance. Every example, calculation and command output on this page was re-run or checked before release; the lab was re-run and the quoted debug lines matched. Review: automated test suite and source check, November 16, 2026.
Spotted an error? Tell us and we will correct it.