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/config with IdentityFile and IdentitiesOnly yes.
  • Keep ~/.ssh at 700 and private keys at 600. SSH ignores a private key that other users can read.
  • Save each server as a Host block with HostName, User and Port so you stop retyping them.
  • When a server is rebuilt, remove its old entry with ssh-keygen -R hostname instead of turning host checking off.

Every SSH error we cover

Connection errors

Authentication errors

Host key errors

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).