Permission denied (publickey)
The server accepts only SSH keys, and none of the keys your Mac offered is in the server's list of allowed keys for that user.
Quick checks
- Check the user name: `git@github.com`, `ubuntu@…`, `ec2-user@…` are all different.
- Run `ssh -v user@host` and read which keys are offered.
- For GitHub, run `ssh -T git@github.com`.
Fixes on Mac
See what ssh is doing
- Run
ssh -v user@host. Look for lines likeOffering public key: …/id_ed25519andAuthentications that can continue: publickey. - If your key is never offered, ssh can't find it or the agent doesn't have it.
- Run
Load the key and keep it in the keychain
- Run
ssh-add --apple-use-keychain ~/.ssh/id_ed25519(enter the passphrase once). - Add to
~/.ssh/config:Host *withAddKeysToAgent yes,UseKeychain yesandIdentityFile ~/.ssh/id_ed25519, so it's loaded automatically.
- Run
Use the right key for each host
- In
~/.ssh/config, setIdentityFileperHostblock, andIdentitiesOnly yesif you have many keys (servers stop after a few failed offers).
- In
Fix permissions
chmod 700 ~/.sshandchmod 600 ~/.ssh/id_ed25519 ~/.ssh/config. ssh ignores private keys that others can read.
Fixes on Windows
OpenSSH on Windows
- Start the agent service (
Get-Service ssh-agent | Set-Service -StartupType Automatic; Start-Service ssh-agent), thenssh-add.
- Start the agent service (
Other devices
On the server
- Your public key must be in
~/.ssh/authorized_keysof the user you log in as, one line per key. - Permissions:
~/.ssh700,authorized_keys600, and the home directory not group-writable.
- Your public key must be in
Still not working?
If keys look right, check the server's auth log (/var/log/auth.log or journalctl -u ssh) for the reason, such as “bad ownership or modes”. Cloud providers may also need the key added through their console rather than by editing files.
See what’s happening
LightAtom's connections view shows the SSH connection from your Mac to the host on port 22, so you can confirm you're reaching the right server.
Frequently asked questions
What does Permission denied (publickey) mean?
The server allows only public-key authentication, and none of the keys your client offered is authorised for that user. Passwords aren't being accepted.
How do I fix Permission denied (publickey) for GitHub?
Add your public key (~/.ssh/id_ed25519.pub) in GitHub › Settings › SSH and GPG keys, load the private key with ssh-add, and test with ssh -T git@github.com.
How do I make my Mac remember the SSH key passphrase?
Run ssh-add --apple-use-keychain ~/.ssh/id_ed25519 once, and put UseKeychain yes and AddKeysToAgent yes in ~/.ssh/config.
Why does ssh say “Too many authentication failures”?
The agent offered too many keys before the right one. Set IdentityFile and IdentitiesOnly yes for that host in ~/.ssh/config.