SSH Authentication Debugging
When to Use This
You have an SSH key installed on a server, but connections fail or hang. This skill provides a systematic debugging methodology.Step 1: Client-Side Verbose Output
Start with triple-verbose to see the full handshake:What to Look For
| Client Output | Meaning | Next Step |
|---|---|---|
Connection refused | SSH service not running or wrong port | Check systemctl status ssh on server |
Connection timed out | Host unreachable or firewall | Check DNS, ping, firewall rules |
No more authentication methods | All auth methods exhausted | Check key is in authorized_keys |
Server accepts key then hangs | Server found key, auth packet lost | See “Postponed publickey” section below |
Permission denied (publickey) | Key not recognized by server | Fingerprint mismatch — see Step 3 |
Key Lines to Find
Step 2: Server-Side Auth Log
On the target server, check the auth log for your connection attempts:What to Look For
| Server Log | Meaning |
|---|---|
Accepted publickey for root from ... ssh2 | Auth succeeded |
Connection closed by authenticating user ... [preauth] | Auth never completed — connection dropped during handshake |
Failed publickey for root from ... ssh2 | Key signature verification failed |
Invalid user ... from ... | Username doesn’t exist on server |
Step 3: Fingerprint Comparison
Verify the key on the client matches the key on the server:SHA256:xxx fingerprint.
Step 4: Permission Check
SSH silently rejects keys if file permissions are wrong:| Path | Permissions | Owner |
|---|---|---|
/root/.ssh/ | 700 (drwx------) | root:root |
/root/.ssh/authorized_keys | 600 (-rw-------) | root:root |
Step 5: Server Debug Mode
The most powerful tool. Run sshd in debug mode on an alternate port:Critical Server Debug Lines
The “Postponed publickey” Pattern
What It Means
In the SSH protocol, public key auth is a two-phase process:- Probe: Client sends key blob (no signature). Server checks
authorized_keys. If found, sendsPK_OK. - Sign: Client signs a challenge with the private key. Server verifies signature.
Common Causes
| Cause | Diagnosis | Fix |
|---|---|---|
| MTU/packet drop | Large signed packet silently dropped by network | Lower MTU: ip link set eth0 mtu 1400 |
publickey-hostbound-v00 incompatibility | OpenSSH 10.x client vs older network infrastructure | Use paramiko or password auth |
| Agent hang | SSH agent can’t sign (locked, crashed) | ssh-add -l to verify, restart agent |
Network Diagnosis
SSH Config Files to Check
Override Files (Ubuntu 24.04)
50-cloud-init.conf— may setPasswordAuthentication yes60-cloudimg-settings.conf— may override toPasswordAuthentication no