/errors/ssh/permission-denied-publickey
Permission denied (publickey) with ssh
- tool
- OpenSSH
- exit code
- 255
- versions
- OpenSSH 8.x – 10.x
- os
- linux, macos, windows
Permission denied (publickey). means the SSH server only allows public-key authentication and rejected every key your client offered; ssh exits with status 255. The server must have your public key in the target user's ~/.ssh/authorized_keys (or in your GitHub or GitLab account), and your client must offer the matching private key.
Diagnose with -v
ssh -v user@server.example.comIn the output, look for:
Offering public key: …— the keys the client tries.Authentications that can continue: publickey— the server accepts only keys.Server accepts key— the key is authorized; if it never appears, none of the offered keys is.
Fixes
Offer the right key:
ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes user@server.example.comInstall your public key on the server (password login must still work for this step):
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server.example.comFix permissions on the server. sshd ignores authorized_keys when the directory or file is writable by others:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keysUse the right user. Cloud images use a default user (ubuntu, ec2-user, admin); GitHub and GitLab always use git.
Replace old key types. OpenSSH 10.0 removed DSA support entirely. Create an Ed25519 key with ssh-keygen -t ed25519.
FAQ
How do I test SSH authentication with GitHub?
Run ssh -T git@github.com. On success GitHub greets you by user name and closes the connection, because it does not provide a shell.