EN · $ USD
VDS and Linux Server Management

How to Fix SSH Connection Refused and Connection Timed Out Errors

7 min read Updated: Sunucu Atlas technical team

In short

SSH connection refused means your packets reached the server but nothing is listening on the SSH port or the connection was actively rejected; timed out means a firewall is dropping the packets or the server is down. To fix it, log in through the VNC console, check the sshd service and the port it listens on, correct your UFW or firewalld rules, and lift the Fail2ban ban if needed.

In this guide
  1. Refused or timed out? What the error message tells you
  2. Step 1: Diagnose from your own computer
  3. Step 2: Access the server through the VNC console
  4. Step 3: Is the sshd service running?
  5. Step 4: Check the firewall
  6. Step 5: Remove the Fail2ban ban
  7. Other possible causes
  8. Quick checklist
  9. How to keep it from happening again
  10. Next step: A VDS that keeps you in control

An SSH connection refused error means you reached the server, but no service is accepting connections on port 22 (or your custom SSH port), or a rule is actively rejecting the connection. Connection timed out means your packets got no response at all: a firewall along the way is silently dropping them, or the server is down. The most common causes are a stopped sshd service, a changed port, a firewall rule and a Fail2ban ban. If you can't get into SSH at all, you can reach the server through the VNC console, independent of the network, and fix the problem in a few minutes.

Refused or timed out? What the error message tells you

The two errors may look alike, but very different things are happening at the network level. Getting the diagnosis right keeps you from wasting time in the wrong place.

Error messageWhat's happening on the networkLikely causes
Connection refusedThe server (or a firewall) is returning a TCP RST or an ICMP “port unreachable” responsesshd isn't running, SSH was moved to another port, a REJECT rule, a Fail2ban ban
Connection timed outPackets get no response at allA firewall DROP rule, UFW enabled before the SSH port was allowed, server down or frozen, wrong IP address, your local network blocking the port
No route to hostNo route to the destination, or rejected via ICMPWrong IP, broken server network configuration, a REJECT rule
Permission denied (publickey)Connection established, authentication failedWrong key or user; not a network problem

Depending on the ban action it uses, a Fail2ban ban can show up as either refused or timed out. So when it “worked yesterday and suddenly stopped today,” always put Fail2ban on your list of suspects.

Step 1: Diagnose from your own computer

First, check whether the server is up and whether the port is reachable.

Windows (PowerShell):

Test-NetConnection 203.0.113.10 -Port 22

Linux / macOS:

nc -vz 203.0.113.10 22
ssh -v root@203.0.113.10

Replace 203.0.113.10 with your own server's IP address. The verbose ssh -v output shows at which stage the connection fails: if it hangs after the Connecting to ... line, it's the network or a firewall; if you get Connection refused right away, it's a service or port problem.

Then run these quick tests:

  • Try from a different network: Tether to your phone's mobile data and try to connect. If that works, your home or office IP address may have been banned by Fail2ban, or your local network may be blocking the port.
  • Does your website load? If there's a site on the server and it loads, the server is running and the problem is limited to SSH.
  • Did you change the port? If you changed the SSH port earlier, specify the right one, like ssh -p 2222 root@IP.

Step 2: Access the server through the VNC console

The VNC console connects you to the virtual machine's screen and keyboard through the hypervisor, giving you a way in that doesn't depend on the server's network settings or firewall. On KVM-based VDS servers, it's the equivalent of sitting in front of a physical server; you can log in with the root user and password even if SSH is completely down.

  1. Open the console (VNC) screen from your VDS management panel. If you can't find console access, open a support ticket for help.
  2. Log in with your username and password. The console's keyboard layout may differ, so be careful with passwords that contain special characters.
  3. If you disabled password login and don't know your root password, use the password reset or rescue options in the panel.
  4. If the server isn't responding, reboot it from the console and watch the boot messages for disk or file system errors.

Step 3: Is the sshd service running?

Once you're logged in through the console, check the SSH service first. On Ubuntu and Debian the service is named ssh; on AlmaLinux and Rocky Linux it's sshd.

sudo systemctl status ssh        # On RHEL derivatives: sshd
sudo ss -tlnp | grep -i ssh
sudo journalctl -u ssh -n 50 --no-pager

If the service has stopped, test the configuration and start it:

sudo sshd -t
sudo systemctl restart ssh
sudo systemctl enable ssh

If sshd -t prints nothing, the configuration is valid. If there's an error, it shows the line number; usually it's a typo in /etc/ssh/sshd_config or a file under /etc/ssh/sshd_config.d/. The service may also fail to start if the disk is completely full; check with df -h.

You changed the port, but SSH still listens on the old one

On newer Ubuntu releases, SSH runs with systemd socket activation by default: ssh.socket decides which port is used. After changing the Port line in sshd_config, you need to run:

sudo systemctl daemon-reload
sudo systemctl restart ssh.socket
sudo ss -tlnp | grep -i ssh

If you don't see the new port in the output of the last command, keep connecting to the old port from your client and check the configuration again.

Step 4: Check the firewall

The classic mistake is enabling UFW without allowing the SSH port, or changing the port and forgetting to open the new one in the firewall.

sudo ufw status verbose
sudo ufw allow 22/tcp          # or: sudo ufw allow 2222/tcp
sudo ufw reload

AlmaLinux and Rocky Linux use firewalld:

sudo firewall-cmd --list-all
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload

If you use raw iptables or nftables rules, check with sudo iptables -L -n -v or sudo nft list ruleset for a DROP or REJECT rule blocking the SSH port. For a correct UFW setup, see the UFW firewall guide.

Step 5: Remove the Fail2ban ban

If you entered the wrong password a few times or an automated tool kept trying to connect, your IP address may be banned. To find your own IP address, open a “what is my IP” site on your local computer, then run this in the console:

sudo fail2ban-client status sshd
sudo fail2ban-client set sshd unbanip 198.51.100.25

If you have a static office IP address, add an ignoreip line to the [DEFAULT] section of /etc/fail2ban/jail.local so you don't get banned again:

[DEFAULT]
ignoreip = 127.0.0.1/8 ::1 198.51.100.25

After the change, run sudo systemctl restart fail2ban. Detailed configuration is in the Fail2ban setup guide.

Other possible causes

  • TCP Wrappers: On older systems, a line like sshd: ALL in /etc/hosts.deny can reject the connection.
  • ListenAddress: If ListenAddress in sshd_config is set to the wrong IP, the service only listens on that address.
  • Network configuration: If the Netplan or network interface settings are broken, the server can't reach the internet at all. In the console, check with ip a and ip route that the IP address and default gateway are correct.
  • Resource exhaustion: When RAM is completely full, the system can't create new processes and SSH may time out. Check with free -h and top in the console.

Quick checklist

If you're short on time, check these in order; most cases are solved within the first four items:

  1. Are you connecting to the right IP address and the right port? (ssh -p PORT kullanici@IP)
  2. Can you connect from a different network, such as mobile data? If so, remove the Fail2ban ban.
  3. Does systemctl status ssh in the console show active (running)?
  4. In the ss -tlnp output, is SSH listening on the port you expect, and is that port open in the firewall?
  5. Are the disk (df -h) and memory (free -h) not full?
  6. Do the IP address and gateway look correct in the ip a and ip route output?

How to keep it from happening again

  1. When changing the SSH port or a firewall rule, don't close your current session; test the new connection from a second terminal before logging out of the old one.
  2. Use key-based authentication instead of passwords; this also makes Fail2ban bans less likely. The steps are in the SSH key generation guide.
  3. Store your root password in a secure password manager; you'll need it for console access.

Next step: A VDS that keeps you in control

The key to fixing SSH problems quickly is full root access and infrastructure where the virtual machine runs its own kernel. Sunucu Atlas Intel Premium VDS plans come with KVM virtualization, root access and automated provisioning; you can manage the firewall, SSH configuration and Fail2ban however you like. For projects that need higher single-core performance, take a look at Ryzen Premium VDS based on the AMD Ryzen 9 5900X. If you want to learn Linux administration or start a small project, SA-XEON-1 with 2 vCPUs and 2 GB of RAM is a good starting point. If you get stuck, open a support ticket for help.

Frequently asked questions

What is the difference between connection refused and connection timed out?

Refused means the server or a rule actively rejected the connection; usually sshd is stopped or the port is wrong. Timed out means no response came back at all; most often a firewall is dropping the packets or the server is down.

How do I know if Fail2ban has banned me?

If you can connect from a different network, such as mobile data, your home or office IP has most likely been banned. From the console, you can see the list of banned IPs with the fail2ban-client status sshd command.

I changed the SSH port and now I can't connect. What should I do?

Log in through the VNC console, check which port SSH is listening on with ss -tlnp, and open that port in the firewall. On newer Ubuntu releases, you need to run systemctl daemon-reload and systemctl restart ssh.socket after changing the port.

What is a VNC console?

A VNC console connects you to a virtual machine's screen and keyboard through the hypervisor. Because it works independently of the server's network settings and firewall, you can log in even when SSH is completely down.

How do I test whether the SSH port is open on Windows?

Run Test-NetConnection IP_ADDRESS -Port 22 in PowerShell. If TcpTestSucceeded is True, the port is reachable and the problem is most likely on the authentication side.

For this guide

Recommended plans

With KVM virtualization and full root access, an Intel Premium VDS or Ryzen Premium VDS puts your SSH, firewall and Fail2ban configuration fully under your control.

SA-XEON-1

XEON
Recommended

2 GB RAM

$2.95/mo

+VAT

  • Processor2 vCPU
  • ModelIntel Xeon
  • Disk30 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

SA-XEON-2

XEON

4 GB RAM

$3.93/mo

+VAT

  • Processor2 vCPU
  • ModelIntel Xeon
  • Disk40 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

SA-XEON-3

XEON

6 GB RAM

$4.91/mo

+VAT

  • Processor2 vCPU
  • ModelIntel Xeon
  • Disk50 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

Intel Premium VDS — tüm paketler Ryzen Premium VDS — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.