SSH Connection Refused? How to Fix Common SSH Errors
SSH connection refused, timed out or permission denied? Find where SSH fails with ssh -v and fix firewall, Fail2ban, key, host key and timeout errors.

Contents
- Start with ssh -v
- Connection refused
- Connection timed out
- Permission denied (publickey)
- Permission denied, please try again
- REMOTE HOST IDENTIFICATION HAS CHANGED
- Host key verification failed
- Too many authentication failures
- no matching host key type found
- Broken pipe and frozen sessions
- SSH errors on Windows
- Last resort: the web console
- SSH access on Nodesty servers
An SSH connection refused error, a connection that times out or a stubborn Permission denied can lock you out of your own server at the worst possible moment. The good news: each SSH error message points at a fairly specific cause, and with the right command you can usually find it in a few minutes.
This guide goes through the most common SSH errors one by one, from network problems to keys and host fingerprints, and shows how to fix each one. If you are new to SSH, start with our What is SSH? guide, which covers connecting and creating keys.
Start with ssh -v
Before guessing, let SSH tell you where it stops. Add -v to your usual command:
ssh -v root@203.0.113.10
The client now prints every step. Look at the last lines before the error:
- It stops after
Connecting to 203.0.113.10 port 22: a network problem (refused or timed out). - It reaches
Server host keyand then fails: a host key problem. - You see
Authentications that can continue: publickey,passwordand the offered keys: an authentication problem.
If that isn't enough, -vvv shows even more detail. The other half of the story is on the server. If you can still get in some other way, follow the SSH log live while you try to connect:
sudo journalctl -u ssh -f
On AlmaLinux the service is called sshd, so use journalctl -u sshd -f. The classic log files are /var/log/auth.log on Ubuntu/Debian and /var/log/secure on AlmaLinux.
| Error message | Most likely cause |
|---|---|
Connection refused | SSH service not running, wrong port |
Connection timed out | Firewall, wrong IP, server down, blocked IP |
Permission denied (publickey) | Wrong key, user or file permissions |
Permission denied, please try again | Wrong password, root password login not allowed |
REMOTE HOST IDENTIFICATION HAS CHANGED | Server reinstalled, or a possible attack |
Too many authentication failures | The client offers too many keys |
no matching host key type found | Old server with outdated algorithms |
Connection refused
ssh: connect to host 203.0.113.10 port 22: Connection refused means the server answered, but nothing accepted the connection on that port. The usual causes are that the SSH service isn't running or that you're connecting to the wrong port.
Check the service on the server (through the web console if you can't get in otherwise):
sudo systemctl status ssh
sudo systemctl enable --now ssh
On AlmaLinux, replace ssh with sshd. If the service won't start, there is often a typo in the configuration. Test it:
sudo sshd -t
The command prints nothing if the configuration is valid, otherwise it names the faulty line. Then check which port SSH really listens on:
sudo ss -tlpn | grep -E 'ssh|:22'
If SSH runs on a port other than 22, connect with ssh -p 2222 root@203.0.113.10. On Ubuntu 22.10 and later, SSH is started through ssh.socket by default; after changing Port in sshd_config, run sudo systemctl daemon-reload and sudo systemctl restart ssh.socket, otherwise the old port stays active.
Connection timed out
Connection timed out means no answer came back at all. Go through these causes in order:
- Wrong IP address. Compare the IP with the one in your customer panel. A typo or an old DNS record is more common than you'd think.
- The server is down. Check in the panel that the server is running.
- A firewall drops the traffic. UFW's default rule silently drops incoming connections, so if you enabled it without allowing SSH, you get a timeout. From the web console:
sudo ufw status sudo ufw allow OpenSSH
If SSH runs on a different port, allow that port instead (sudo ufw allow 2222/tcp). On AlmaLinux with firewalld, usesudo firewall-cmd --permanent --add-service=sshfollowed bysudo firewall-cmd --reload. More in our How to use UFW guide. - Your IP is banned by Fail2ban. After a few failed logins (for example with an old saved password), Fail2ban blocks your IP. Depending on the ban action, this shows up as a timeout or as
Connection refused.
To check from your own computer whether the port is reachable at all:
nc -zv 203.0.113.10 22
In PowerShell, Test-NetConnection 203.0.113.10 -Port 22 does the same.
Unbanning your IP in Fail2ban
Connect from another network (for example your phone's hotspot) or through the web console, then:
sudo fail2ban-client status sshd
sudo fail2ban-client set sshd unbanip 198.51.100.7
The first command lists the banned IPs, the second removes yours. If you have a fixed IP address, add it to ignoreip in /etc/fail2ban/jail.local so it is never banned; see our How to install Fail2ban guide.
Permission denied (publickey)
This message means the server only accepts key login (PasswordAuthentication no) and none of the keys you offered was accepted. Check these points:
Are you logging in as the right user? Keys are tied to a user. A key in /root/.ssh/authorized_keys does not work for ubuntu@..., and the other way round. On many cloud images the default user is ubuntu, debian or almalinux and root login is disabled; at Nodesty, the user name appears in the customer panel.
Are you sending the right key? If your key isn't in the default location, specify it:
ssh -i ~/.ssh/my_server_key root@203.0.113.10
In the ssh -v output, Offering public key lines show which keys your client tries.
Are the permissions on the server correct? By default SSH ignores authorized_keys if the folder or file can be written by others. Fix it for the relevant user (here alice):
sudo chown -R alice:alice /home/alice/.ssh
sudo chmod 700 /home/alice/.ssh
sudo chmod 600 /home/alice/.ssh/authorized_keys
The home folder itself must not be writable by the group or others either. In the server log, this problem shows up as Authentication refused: bad ownership or modes. Our Linux file permissions guide explains these numbers, and How to add a user on Linux shows how to set up a key for a new user.
Is your private key too open? On your own computer, the private key must be readable only by you; otherwise you get UNPROTECTED PRIVATE KEY FILE and SSH ignores the key. Fix it with chmod 600 ~/.ssh/id_ed25519.
Permission denied, please try again
Here the server asks for a password, but the login fails. Besides a simple typo (nothing appears on screen while you type the password, and the keyboard layout matters), the most common cause is that root is not allowed to log in with a password. OpenSSH's default is PermitRootLogin prohibit-password: root may log in with a key, but not with a password, even if the password is correct.
To see the settings sshd is really using:
sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication'
On Ubuntu and Debian, files in /etc/ssh/sshd_config.d/ are read before the rest of sshd_config, and for most settings the first value wins. So a line like PasswordAuthentication no in a file such as 50-cloud-init.conf can override what you set in the main file. The safer route is not to allow root password login at all: log in with a regular user and sudo, or use a key. Our Linux server security guide explains why.
REMOTE HOST IDENTIFICATION HAS CHANGED
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
SSH remembers each server's fingerprint in ~/.ssh/known_hosts, and this time the server presented a different one. The harmless and most common reason is that you reinstalled the server or that the IP now belongs to a new server. In that case, delete the old entry and connect again:
ssh-keygen -R 203.0.113.10
For a non-standard port, the entry looks like ssh-keygen -R "[203.0.113.10]:2222".
If you haven't changed anything, take the warning seriously: it can also mean that someone is intercepting the connection (a man-in-the-middle attack). Before you accept the new key, compare the fingerprint. In the server's web console, run ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub and check that it matches the fingerprint SSH shows you.
Host key verification failed
This error appears after the warning above, if you answered no to the fingerprint question, or when SSH runs without a terminal (in a script, cron job or CI pipeline) and the server isn't in known_hosts yet. For the first case, follow the previous section. For automated jobs, add the host once after checking the fingerprint:
ssh-keyscan -H 203.0.113.10 >> ~/.ssh/known_hosts
Don't turn off StrictHostKeyChecking permanently; it removes exactly the protection described above.
Too many authentication failures
Received disconnect ... Too many authentication failures usually means your SSH agent holds several keys and offers them one after another. The server allows only a limited number of attempts (MaxAuthTries is 6 by default), so you are disconnected before the right key gets its turn. Tell SSH to use only the key you specify:
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 root@203.0.113.10
To make it permanent, put it in ~/.ssh/config:
Host myserver
HostName 203.0.113.10
User root
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
After that, ssh myserver is enough.
no matching host key type found
Unable to negotiate with 203.0.113.10 port 22: no matching host key type found. Their offer: ssh-rsa appears when a new client meets a very old server. Since OpenSSH 8.8, the old ssh-rsa (SHA-1) signature is disabled by default. As a temporary workaround, you can allow it for this connection only:
ssh -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa root@203.0.113.10
The same applies to no matching key exchange method found, which you can work around with -o KexAlgorithms=+diffie-hellman-group14-sha1. These are emergency measures: the real fix is to update the server's operating system or OpenSSH.
Broken pipe and frozen sessions
If your session freezes after some idle time or ends with client_loop: send disconnect: Broken pipe, a router or firewall along the way has dropped the idle connection. Have your client send a small keepalive message regularly by adding this to ~/.ssh/config:
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
The client then sends a keepalive every 60 seconds and gives up after three unanswered ones. On the server, ClientAliveInterval in sshd_config does the same in the other direction. Run long jobs such as updates or backups inside tmux or screen; they keep running even if the connection drops, and you can reattach later.
SSH errors on Windows
Windows 10 and 11 include the OpenSSH client, so all the commands above work in PowerShell. Your configuration and keys live in C:\Users\<name>\.ssh\. A few Windows-specific issues:
sshis not recognized: Install the OpenSSH client under Settings, Optional features.Bad permissionsfor the private key: Windows SSH also refuses keys that other users can read. Remove inherited permissions and grant access only to yourself:icacls $env:USERPROFILE\.ssh\id_ed25519 /inheritance:r /grant:r "$($env:USERNAME):(R)"- PuTTY and
.ppkfiles: PuTTY uses its own.ppkkey format and can't read OpenSSH keys directly. Open your key in PuTTYgen with Conversions, Import key and save it as.ppk; for the other direction, use Conversions, Export OpenSSH key. PuTTY'sServer refused our keycorresponds toPermission denied (publickey)and has the same causes.
Last resort: the web console
If none of this works because you can't get into the server at all, for example because of a firewall rule, a broken sshd_config or a lost key, you still have the provider's web console (VNC). It shows the server's screen independently of SSH and the network configuration. Log in there with the user and password, fix the setting, start the SSH service again and test the connection from a second terminal before you close the console.
SSH access on Nodesty servers
Nodesty AMD Ryzen 9 9950X VPS and AMD EPYC 7763 VPS plans come with NVMe disks and full root access, and OpenSSH is preinstalled on Ubuntu, Debian and AlmaLinux. If SSH access breaks, the web console in the Nodesty customer panel gives you the server's screen independently of SSH, and you can reinstall the operating system from the panel if needed. Daily backups are free on VPS plans and are kept for 7 days.
Frequently Asked Questions
What is the difference between Connection refused and Connection timed out?
Connection refused means your request reached the server, but nothing is listening on that port or a firewall actively rejected it. Connection timed out means no answer came back at all, usually because a firewall silently drops the traffic, the IP address is wrong or the server is down.
How do I see why my SSH connection fails?
Run ssh -v user@ip to see each step of the connection, or ssh -vvv for even more detail. The last lines before the error show whether the connection, the host key check or authentication failed. On the server, the SSH log in journalctl or /var/log/auth.log shows the reason from the other side.
Why do I get Permission denied (publickey) even though I added my key?
Usually the key is in the wrong user's authorized_keys file, the file or the .ssh folder has the wrong permissions or owner, or your client offers a different key. Use chmod 700 for .ssh and chmod 600 for authorized_keys, and select the right key with ssh -i.
Is it safe to delete the old entry when I see REMOTE HOST IDENTIFICATION HAS CHANGED?
Only if you know why the key changed, for example because you reinstalled the server. In that case, delete the old entry with ssh-keygen -R and connect again. If you changed nothing, compare the fingerprint through the web console first, because the warning can also mean someone is intercepting the connection.
My IP was banned by Fail2ban. How do I get back in?
Connect from another IP address or through your provider's web console and run fail2ban-client set sshd unbanip followed by your IP. To keep it from happening again, add your own fixed IP address to ignoreip in jail.local.
How do I stop SSH sessions from freezing or disconnecting?
Add ServerAliveInterval 60 to your ~/.ssh/config file so your client sends a small keepalive message every minute. Idle connections are then not dropped by routers or firewalls along the way. For long jobs, run them inside tmux or screen so they keep running if the connection drops.
About the author
Nodesty Team · Infrastructure & Support
The Nodesty team runs our servers, network and DDoS protection day to day and answers customer support requests around the clock. These guides come from that work.
Related articles

How to Install a LEMP Stack on Ubuntu and Debian
How to install a LEMP stack on Ubuntu and Debian: Nginx, MariaDB and PHP-FPM, the server block, the PHP socket, permissions, HTTPS and common errors.

How to Use tmux: Keep Programs Running After SSH Closes
Learn how to use tmux on a Linux server: keep programs running after SSH closes, detach and reattach sessions, split panes, scroll and fix common errors.

How to Deploy a Node.js App with PM2 and Nginx
How to deploy a Node.js app on a Linux VPS: Node.js LTS, npm ci, PM2 with autostart and reload, an Nginx reverse proxy, HTTPS, updates and common errors.