Common SSH Errors and How to Fix Them
Test setup: Ubuntu 24.04 with OpenSSH 9.6p1 (client and server), November 29, 2026. Each fix linked below says whether we reproduced that error.
Every SSH error happens at one of four stages: turning the hostname into an address, reaching the server, logging in or checking that the server is the one you saw last time. The message tells you which stage failed, and that decides the fix.
| Message starts with | Stage that failed | Usual cause |
|---|---|---|
Could not resolve hostname |
Finding the server | Typo, missing DNS record or a Host alias that isn’t in your config |
Connection refused / timed out / No route to host |
Reaching it | sshd not running, wrong port, a firewall |
Permission denied (publickey) |
Logging in | Wrong key, wrong user or file permissions |
REMOTE HOST IDENTIFICATION HAS CHANGED / Host key verification failed |
Checking the server | The server was rebuilt, or the address now points elsewhere |
We reproduced the name, connection and login errors against a local OpenSSH server, so those messages are copied from a real terminal.
Diagnose before you fix
Run the same command with -v:
ssh -v user@example.com
Read from the bottom up. If the output stops before any Connecting to line, it’s a name problem. If it stops at connect to host ... port 22, it’s a network or server problem. If you see Offering public key followed by No more authentication methods to try, the server rejected your key.
Check that SSH is running, and restart it
From your own machine, nc -zv example.com 22 tells you whether the port answers before SSH gets involved. On the server:
sudo systemctl status ssh # sshd on Fedora, RHEL and Arch
sudo systemctl restart ssh # or: sudo service ssh restart on older systems
sudo sshd -t # check the config for errors first
On Ubuntu 22.10 and later, a changed Port needs sudo systemctl daemon-reload and sudo systemctl restart ssh.socket instead; our connection refused fix explains why.
Setup checklist that prevents most SSH errors
- Generate an ed25519 key, use one key per purpose and name it in
~/.ssh/configwithIdentityFileandIdentitiesOnly yes. - Keep
~/.sshat700and private keys at600. SSH ignores a private key that other users can read. - Save each server as a
Hostblock withHostName,UserandPortso you stop retyping them. - When a server is rebuilt, remove its old entry with
ssh-keygen -R hostnameinstead of turning host checking off.
Every SSH error we cover
Connection errors
- SSH Connection Refused: How to Fix It (Port 22)Connection refused means the server answered but nothing was listening on that port. Check that sshd is running, that you use the right port and the firewall.
- SSH Could Not Resolve Hostname: Name or Service Not KnownSSH couldn't turn the hostname into an IP address. Check it for typos, add the Host alias to ~/.ssh/config, and confirm it resolves in DNS or your hosts file.
Authentication errors
- Permission Denied (publickey): How to Fix It in SSH and GitThe server didn't accept any key you offered. Check which key SSH sends, that it's in authorized_keys or on GitHub, the username and the file permissions.
- How to Generate an SSH Key (ed25519) on Mac, Linux, WindowsRun ssh-keygen -t ed25519, add the key to ssh-agent and paste the .pub file into GitHub or authorized_keys. Commands for Mac, Linux and Windows, with checks.
Host key errors
- Remote Host Identification Has Changed: How to Fix ItThe server's host key no longer matches the one you saved. Confirm the change is expected, then remove the old key with ssh-keygen -R and connect again.
FAQ
How do I debug an SSH connection?
Add -v to the command, for example ssh -v user@host. The output shows each stage in order, so the last lines tell you whether SSH failed to find the host, reach it or log in. Use -vvv for more detail.
What port does SSH use?
Port 22 by default. If the server listens on another port, pass it with -p 2222 or set Port for that host in ~/.ssh/config.
Why does SSH say permission denied when my password is right?
Many servers turn password logins off and accept keys only. The error then lists (publickey). See Permission denied (publickey).
