SSD Nodes Learn Hosting plans →
How to do am Matt ConnorBy Matt Connor · Updated 2026-10-28

SSH Connection Refused vs Timed Out: Wetin E Mean

See why SSH dey show “Connection refused” or “Connection timed out”, how timing help, and the correct test to run from your machine or server.

Wetin “Connection refused” and “Connection timed out” mean for SSH

SSH connection refused and SSH connection timed out na opposite failures, so fix for one no be fix for the other. Refused mean say rejection come back. Most times, na server kernel dey talk say “nothing dey listen here”; sometimes na firewall for the path wey set to reject instead of drop. Timed out mean say no reply reach before your client give up. Most times, na because firewall discard the packet; sometimes server too busy to accept new connection. Refused usually na service problem for server. Timed out usually na path problem before server.

Read the exact line wey your client print, because na the wording carry the full diagnosis.

ssh: connect to host 203.0.113.10 port 22: Connection refused
ssh: connect to host 203.0.113.10 port 22: Connection timed out

Timing na the second clue. Refused go come back immediately, roughly for the time wey one round trip take. Timed out go stay for many seconds before e print, because client dey retransmit before e give up. macOS print Operation timed out for the same condition. If the protocol still new to you, how SSH dey work and wetin sshd dey do na the background wey this guide assume.

Why “Connection refused” na good news

Refused usually mean TCP (transmission control protocol) reset. Your client send SYN packet go port 22. E cross internet, reach the server network stack, and kernel see say no socket dey listen for that port, so e answer with RST (reset) packet. Your SSH client turn that RST into the words Connection refused.

When na the server own kernel send am, that one packet wey return prove plenty things. The address correct. The host dey powered on and routing dey work. Nothing for the path silently discard traffic go that port, because something return from the far end. So the remaining suspects dey inside the server itself, except firewall wey dey in front of am and set to reject instead of drop. That firewall fit produce the same refusal without the server take part at all.

  • sshd no dey run, because e fail to start or dem never enable am.
  • sshd dey listen for another port, usually after hardening change.
  • sshd bind to one address, like ListenAddress 127.0.0.1, so na only the server itself fit reach am.
  • Firewall set to reject instead of drop, so the firewall answer on behalf of the host with RST or ICMP port unreachable message, and your client print Connection refused for either one. The ufw reject action and nftables rule wey end with reject with tcp reset both do this. Plain iptables REJECT rule dey do am too; by default, e send ICMP port unreachable, or TCP reset with --reject-with tcp-reset.

One more case fit look like those ones but e no be the same: you type address wey belong to another live host. That host answer your SYN, no SSH dey run for port 22, and e politely refuse you. Confirm the address before you spend one hour for the wrong server. If you know wetin listening port really be for Linux, the rest of this section go read faster.

How to fix Connection refused

You no fit fix this over SSH, because na SSH dey spoil. Open your provider web console or serial console, sign in there, then run these commands one after another.

systemctl status ssh
sudo ss -tlnp
sudo sshd -T | grep -Ei '^(port|listenaddress|addressfamily)'

systemctl status ssh dey use the unit name for Ubuntu and Debian. For RHEL and rebuilds like AlmaLinux, the unit na sshd. ss -tlnp dey list every TCP socket wey dey listen, together with the process wey own am, and na the correct source of truth: if no line mention sshd, nothing dey listen, no matter wetin the config file claim. sshd -T dey print the effective configuration after e merge every Include file, and na there forgotten port for /etc/ssh/sshd_config.d/ go show.

Read the address column well. 0.0.0.0:22 mean every IPv4 address for the machine. [::]:22 mean every IPv6 address. 127.0.0.1:22 mean say na loopback only, so no remote client fit reach sshd at all, while local ssh localhost dey work perfectly. Wetin remote client go see depend on the firewall wey dey front: if nothing dey filter port 22, e go get Connection refused. But firewall wey dey drop the attempt, like ufw with default deny (DROP) policy for incoming connections and no SSH rule, go turn the same mistake to timeout.

If nothing dey listen, start the service and read the failure when e no gree start.

sudo sshd -t
sudo systemctl enable --now ssh
sudo journalctl -u ssh -n 50 --no-pager

sshd -t dey parse the configuration and print the file and line number of bad directive without touching the service wey dey run. Run am before every restart, because rejected config mean say sshd go exit when e start, and your next connection go get refused.

Ubuntu socket activation trap

Ubuntu 24.04 release one systemd socket unit for OpenSSH. If dem enable this unit, systemd go hold the listening port and start sshd only when request come. One systemd generator dey copy Port and ListenAddress from sshd_config enter the socket settings. But systemd only dey run generators when system boot or when e reload configuration. So, setting Port 2222 and restarting ssh no dey enough. The server go still answer for the old port. Check which mode your system dey use before you edit anything.

systemctl is-enabled ssh.socket
systemctl status ssh.socket

If the socket dey enabled, set the port for sshd_config as usual. Then regenerate the socket settings and restart the socket instead of the service.

sudo sshd -t
sudo systemctl daemon-reload
sudo systemctl restart ssh.socket

daemon-reload na the step wey people dey miss. For system wey dey run, na this step dey run the generator again. Reboot go run am too. Use sudo ss -tlnp confirm say the new port na the one wey system dey hold. Changing the port na normal step for hardening SSH for VPS, but na the step wey dey lock people out most often.

Wetin “Connection timed out” mean when no answer return

Timeout na silence. Your client send SYN, resend am several times for one or two minutes, and no reply come before e give up. By itself, this no prove anything about the server. Most times, dem discard the packet before e reach anything wey fit answer. The connect(2) man page still list server wey too busy to accept new connections as one possible cause, so host wey get heavy load fit also time out. If the line instead show Connection timed out during banner exchange, TCP don connect but sshd never send e greeting, so handle am like the kex_exchange_identification case wey dey further down, no be path problem.

Silence na exactly wetin DROP rule dey produce, and the dropping na deliberate. Rejection dey tell anybody wey dey scan say the host dey exist, so ufw and most cloud providers' network firewalls dey discard unwanted packets and send nothing back. Your timeout usually mean say firewall dey do e work for port wey you want make open.

  • The address wrong: DNS record still dey point to server wey you rebuild, or typo carry you go address wey nobody dey use.
  • The host no dey up: e power off, or e dey halfway through reboot. Provider suspension because of billing go look the same from outside.
  • Host firewall dey drop port 22, most often because ufw enable run before any allow rule exist.
  • Provider firewall wey dey front of the instance dey drop am, and operating system no see the packet at all.
  • Your own network dey block outbound port 22, and this common for office and hotel connections.
  • Host dey up but e too overloaded to accept new connections. This one rare, and provider console usually show am as very high load.

Run the test from the correct side of the connection

Na here people dey make mistake wey dey waste pass time. You no fit diagnose dropped packet from inside the box wey the packets no dey reach. If you fit log in to run the command, you for no get this problem. Every command for this section dey run for your own machine.

getent hosts vps.example.com
ssh -G vps.example.com | grep -Ei '^(hostname|port|user)'
ssh -vvv -o ConnectTimeout=10 user@vps.example.com
nc -vz -w 5 203.0.113.10 22

getent hosts dey show the address wey your machine go really use. This one fit catch stale DNS record within seconds. ssh -G dey print the settings wey your client apply after e read ~/.ssh/config. So e fit catch old Host block wey dey quietly change the hostname, port, or user. ssh -vvv dey show how far the attempt reach. If the last line talk say e dey connect to the address, then e pause for long time, na timeout be that. If one line report the remote OpenSSH version, TCP don already succeed, and the real problem dey further ahead. Unable to negotiate line mean say both sides no get common key exchange or host key algorithm. If none of these happen, na almost always authentication problem. For Windows, Test-NetConnection 203.0.113.10 -Port 22 for PowerShell dey replace nc.

Test the port, no be the host. Failed ping no prove anything, because many providers dey filter ICMP (internet control message protocol) for the edge. Successful ping no prove anything too, because e no talk anything about port 22.

Then change the one variable wey no command fit change for you: your network. Try again from phone hotspot. If the hotspot connect and your desk network no connect, the block dey your side of the internet, or dem don ban your office address for the server.

Provider firewall wey you no fit see from server

Plenty VPS panels get network firewall, wey dem sometimes dey call security group or cloud firewall. E dey run upstream from your instance and e get im own rule list. ufw status for server no fit see am. Na why people dey often talk say, “but I don already allow port 22.” Open the panel and read that list before you change any rule for the box.

One command fit settle the matter, but you need console access. Start am for server, then try connect from your laptop while e dey run.

sudo tcpdump -ni any tcp port 22

If nothing show while your client dey try connect, the packets dey get discarded before dem reach operating system. This means say the problem dey with provider firewall or the route go the host. If SYN packets arrive but no reply comot, the drop dey local and na ufw or nftables cause am. That one test divide timeout problem into two, so e make sense to use console.

ufw order, IPv6, and ban wey you give yourself

The ufw order mistake dey lock out more people pass anything else for here. sudo ufw enable dey apply default policy wey deny incoming immediately, so if SSH rule no dey there, your current session go survive because of established state, while every new connection go time out. Allow first, then enable.

sudo ufw allow OpenSSH
sudo ufw status verbose

The OpenSSH application profile cover port 22 only. If you plan move SSH go 2222, the rule wey you need na sudo ufw allow 2222/tcp, add am before you change the port, no be after. The wider rule set dey covered for ufw firewall basics for VPS, and the safe order na part of wetin to do for the first ten minutes on new VPS.

IPv6 fit produce timeout wey go look supernatural. If hostname get AAAA record and your own connection get working IPv6, your client normally go try IPv6 first. So, server wey IPv6 rules dey missing go hang while plain IPv4 attempt go work. Separate the two by hand.

ssh -4 user@vps.example.com
ssh -6 user@vps.example.com

If -4 connect and -6 time out while your machine dey reach other IPv6 hosts without problem, the IPv6 path go this server na the problem. But these two tests no fit tell you where for that path. Start with the server own IPv6 rules, and how to open the same port for IPv6 inside ufw go guide you through am. Then check the provider side, because provider firewall or security group dey keep separate IPv6 rules, and the network need IPv6 route to the instance. AWS, for example, list IPv6 route (::/0) go internet gateway, security group rule for your IPv6 address on port 22, and network ACL rules wey allow inbound and outbound IPv6 traffic. If -6 fail immediately with Network is unreachable, the usual cause na say your own machine no get IPv6 route. But the same error fit show when firewall for the path reject you with ICMPv6 no-route message. If ssh -6 or nc -6 reach other IPv6 hosts from the same machine, check the server side after all.

You fit don ban yourself too. fail2ban dey monitor the authentication log and insert firewall rule against addresses wey fail repeatedly, so wrong key or script wey dey retry for background fit lock out whole office address. Ban wey drop connection dey look like timeout. Ban wey reject connection dey return Connection refused with fail2ban stock iptables and nftables actions, or No route to host if the action reject with host unreachable type. From the console:

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

Adding your own address to ignoreip na part of working fail2ban setup for Ubuntu 24.04.

Errors wey no be refused or timed out

No route to host mean say ICMP unreachable message come back. Either your own machine no get route go that network, or something for the path answer with administrative rejection, like an iptables REJECT rule wey set to icmp-host-prohibited or icmp-admin-prohibited. REJECT rule wey no get type dey send port unreachable, and your client report am as Connection refused instead.

Network is unreachable usually na your own machine dey talk. E no get route go that destination, and na the normal answer when hostname resolve only to IPv6 address for IPv4-only connection. Sometimes firewall for the path dey send am deliberately, for example, nftables rule wey reject with icmpv6 type no-route.

kex_exchange_identification: Connection closed by remote host mean say TCP connect, then server hang up before key exchange finish. The port dey open and sshd dey alive, so check server load, MaxStartups, or ban wey take effect while you dey connect.

Received disconnect: Too many authentication failures fit still come for connection wey dey work well. E mean say your agent offer every key wey e hold until server stop listening. So the fix na make the attempt use one key only, no be anything for this guide.

Permission denied (publickey) mean say you reach authentication but fail there. Network dey fine and firewall dey fine, so nothing for this guide apply. Go fixing Permission denied (publickey) on SSH instead.

How to enter again, and how to prevent another lockout

Every serious VPS host dey give you console wey no depend on the guest network: na serial console, or browser-based VNC screen. This console na the recovery route for both branches of this guide, because e go still work when sshd stop and when firewall rule discard everything. Find am for the panel, sign in as root or your normal user, then run the checks above. If you never set root password, most panels fit reset one for you.

Where console no dey, use provider rescue mode as fallback. E go boot small recovery system and mount your disk, so you fit edit /etc/ssh/sshd_config or delete firewall rule offline, then reboot.

Two habits fit prevent the next lockout. Keep second SSH session open whenever you edit sshd or firewall, because that session go remain active through established state while you test fresh one. Also, set automatic undo before risky firewall change.

sudo systemd-run --unit=ufw-rollback --on-active=10min /usr/sbin/ufw disable
sudo systemctl stop ufw-rollback.timer

The first line schedule ufw to switch itself off after ten minutes. Apply your new rules, open new SSH session to confirm say dem work, then run the second line to cancel the rollback. If you lock yourself out instead, wait ten minutes and the firewall go stand down by itself. E go leave the box without filtering until you enable ufw again, so use this while you dey for the keyboard, no be as permanent arrangement.

Das order wey you suppose follow

  1. Read the error text, and notice how long e take before e show.
  2. Refused: go console and check sudo ss -tlnp for listening socket, the port wey e dey use, and the address wey e bind to.
  3. Timed out: from your own machine confirm the address first. Then check provider firewall for the panel, and after that check host firewall for the box.
  4. If none of those strings show, and e no be route error: TCP connection don already happen. Treat am as key exchange, authentication, or server-load question, no be network question.

FAQ

Why SSH dey talk say "Connection refused" when sshd dey run?

Because na socket dey return the refusal, no be the service, and sshd wey dey run still fit refuse your connection. Open provider console and run sudo ss -tlnp. Socket for 127.0.0.1:22 no fit receive connection from any remote client, because na loopback only dem bind am to. So remote attempts go get refusal when nothing dey filter port 22, and dem go time out when firewall drop dem first. Socket for another port mean say nothing dey listen on 22. Clients wey still dey use 22 go get refusal there, or time out if firewall drop port 22. If another listener still hold 22, dem go connect to that one instead. If systemd socket activation dey use, ssh.socket dey hold the port and e go only apply Port change from sshd_config after sudo systemctl daemon-reload and restart of ssh.socket, or after reboot. So check systemctl is-enabled ssh.socket too. A ufw reject rule fit also return refusal on behalf of the host, so read sudo ufw status verbose before you draw any conclusion.

Why SSH dey time out when ufw don already allow port 22?

Because timeout mean say no answer return, and ufw no be the only firewall for the path. Most VPS panels dey run network firewall in front of the instance, and operating system no dey see wetin that firewall drop. From the console, run sudo tcpdump -ni any tcp port 22 and try connect from your laptop while e dey run. If no packet enter, na upstream drop for the panel. If packets enter but no reply commot, na local drop for ufw or nftables.

Failed ping mean say my VPS dey down?

No. Plenty providers dey filter ICMP for network edge, so server wey dey serve traffic normally fit ignore every ping wey you send. Successful ping weak for the other side too, because e no tell you whether port 22 dey open. Test the port itself with nc -vz -w 5 203.0.113.10 22 from your own machine, or with Test-NetConnection 203.0.113.10 -Port 22 for PowerShell on Windows.

I change SSH port and now nothing dey connect. Wetin go wrong?

Two things fit cause this, depending on the order. If firewall never get rule for the new port, attempts to the new port go time out while port 22 go refuse. So sudo ufw allow 2222/tcp suppose dey before the port change, no be after am. If the box dey use systemd socket activation for SSH, Port 2222 for sshd_config go only take effect after sudo systemctl daemon-reload and sudo systemctl restart ssh.socket, or after reboot. Until then, systemd go continue hold the old port. systemctl is-enabled ssh.socket go tell you which mode you dey use. Recover through provider console, fix the one wey apply, then connect with ssh -p 2222 user@203.0.113.10 once sudo ss -tlnp show the new socket.

Dis article help you?