← Back to all fixes

SSH: Permission denied (publickey)

The Issue

`ssh user@host` returns: `Permission denied (publickey,gssapi-keyex,gssapi-with-mic)`

Root Cause

SSH key not added to authorized_keys, wrong permissions on .ssh directory, or sshd not accepting the key type.

How to Fix
  1. Check .ssh directory permissions on the server: `chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys`
  2. Verify your public key is in authorized_keys: `cat ~/.ssh/authorized_keys`
  3. Add your key: `ssh-copy-id -i ~/.ssh/id_rsa.pub user@host`
  4. Check sshd config allows pubkey: `grep PubkeyAuthentication /etc/ssh/sshd_config` should be `yes`
  5. Debug with verbose mode: `ssh -vvv user@host` and look at which keys are tried