Linux SSH Key Errors — Agent Forwarding, Host Key & Permission Denied (publickey)
Warningnetwork
Overview
Fix SSH key errors including 'Permission denied (publickey)', host key verification failed, agent forwarding issues, and key format incompatibilities.
Key Details
- 'Permission denied (publickey)' means the server rejected all offered keys
- Host key verification failed: server's host key changed (possible MITM or server reinstall)
- SSH keys must have strict permissions: private key 600, .ssh dir 700
- ssh-agent stores decrypted keys in memory for convenient reuse
- Agent forwarding (-A) allows using local keys on remote servers but has security implications
Common Causes
- Public key not in ~/.ssh/authorized_keys on the server
- Wrong permissions on private key file (must be 600 or more restrictive)
- SSH server configured to reject the key type (e.g., RSA disabled, only Ed25519 accepted)
- Wrong user: trying to SSH as user A but key is authorized for user B
- Server host key changed: legitimate (reinstall) or suspicious (MITM)
Steps
- 1Debug connection: ssh -vvv user@host to see which keys are offered and rejected
- 2Fix key permissions: chmod 600 ~/.ssh/id_rsa && chmod 700 ~/.ssh
- 3Copy key to server: ssh-copy-id user@host (adds your public key to authorized_keys)
- 4For host key change: ssh-keygen -R hostname (removes old host key from known_hosts)
- 5Check sshd config: cat /etc/ssh/sshd_config — look for PubkeyAuthentication and AuthorizedKeysFile
Tags
linuxsshkeyauthenticationpermission-denied
More in Network
windows-651-pppoe-connection-failedWindows Error 651 — PPPoE Connection Failed
Warningwindows-691-authentication-failedWindows Error 691 — Authentication Failed
Warningwindows-720-ppp-connection-failedWindows Error 720 — PPP Connection Failed
Errorwindows-800-vpn-tunnel-failedWindows Error 800 — VPN Tunnel Failed
Warningwindows-network-error-619Windows VPN Error 619 — Connection Could Not Be Established
Warningwindows-network-error-868Windows VPN Error 868 — Remote Server Not Resolved
WarningFrequently Asked Questions
The server does not have your public key, or the key file has wrong permissions. Use ssh -vvv to debug and ssh-copy-id to install keys.