What does "Connection refused" tell me?
That your packets reached a host and the host answered "nothing here" with a TCP reset or an ICMP rejection. This is useful: the network path works and the address is alive. Compare it with "Connection timed out", which means packets disappeared, and with "Connection reset by peer", which means the connection opened and was then cut. A refusal narrows the problem to the port on that machine, or a firewall that rejects instead of dropping.
Is the machine actually ready?
Check the panel first. A machine you just ordered or reinstalled shows Installing until the image is written and the system boots; SSH answers only after it shows Powered on with its address. Powered-off machines do not refuse connections, they time out, so a refusal during installation usually comes from an early boot stage. Wait until the status settles, then try again.
Am I using the right address and port?
Surprisingly often, the answer is no. Copy the IPv4 address straight from the panel, and remember any port change you made:
nc -vz -w 5 203.0.113.25 22 nc -vz -w 5 203.0.113.25 2207
A succeeded on one port and refused on the other ends the search. If you use a host alias from ~/.ssh/config, run ssh -G myalias | grep -E '^(hostname|port) ' to see what the client really connects to.
Is sshd running and listening on the public address?
If you still have any session open, or another user does, look at the service and its sockets:
systemctl status ssh --no-pager # sshd on Rocky, AlmaLinux, CentOS Stream ss -tlnp | grep -E 'sshd|systemd'
Three outcomes are common. Nothing listening: the service is stopped or failed, and journalctl -u ssh -n 40 says why, typically a syntax error after an edit. Listening on 127.0.0.1:22 only: a ListenAddress line limits it to loopback; remove it or add the public address. Listening on another port: a drop-in changed it, and sshd -T | grep ^port shows the value. On Ubuntu 24.04, systemd holds the listening socket for ssh, so the process name in ss output may be systemd rather than sshd.
Is a firewall rejecting the port?
Firewalls configured with reject rules produce refusals that look exactly like a stopped service. Check the rules for the SSH port:
| Tool | Command |
|---|---|
| ufw | ufw status numbered |
| firewalld | firewall-cmd --list-all |
| nftables | nft list ruleset | grep -n -E 'dport|reject' |
| FreeBSD pf | pfctl -sr |
The usual mistake is enabling ufw or firewalld without first allowing SSH, or moving SSH to a new port without allowing it. On SELinux systems a non-standard port also needs an ssh_port_t label, otherwise sshd fails to bind and the port refuses; Change the SSH port covers that.
What if I have no session left at all?
Try a reboot from the panel first. It clears a hung daemon or a rule that was added at runtime but never saved, and it costs a minute. If the bad setting is saved on disk, the reboot will not help. Without an out-of-band console in the offer, the remaining route is a reinstall from the panel, which erases the drives and installs a fresh image with a new root password. That is why the safe habits matter: validate with sshd -t, keep a session open while testing, and use a timed rollback for firewall changes, for example scheduling systemctl stop nftables with systemd-run --on-active=5min before applying new rules.
Could the problem be on my side?
Rarely for a refusal, but possible. Some office and hotel networks block outbound port 22 with a reject. Test from a phone hotspot: if it works there, your local network is the cause. A local firewall or antivirus suite can also refuse outbound SSH. Running ssh -v shows connect to address ... port 22: Connection refused immediately in either case, so the network test is the quickest way to tell them apart.
How do I stop it from happening again?
- Change sshd settings in drop-in files and run
sshd -tbefore every restart. - Allow the SSH port before enabling any firewall.
- Keep your public key saved in the panel, so a reinstall gives you key access immediately.
- Write down any custom port in your SSH config, not only in your memory.
Keep Reading
Fix "Connection reset by peer"
Find out why sshd hangs up mid-handshake: ban lists, MaxStartups throttling, broken host keys, idle timeouts or MTU trouble.
OpenChange the SSH port
Move sshd off port 22 on Ubuntu, Debian, Rocky, AlmaLinux and FreeBSD without locking yourself out of the machine.
OpenEnable SSH on Debian
Install, start and check the OpenSSH server on Debian 13 and Debian 12, then lock it down before exposing the box.
OpenServers in Phoenix
Desert location for the US Southwest and West Coast, a calm western anchor for a two-city setup at the same price.
OpenFAQ
Quick Answers
Refused means the host actively rejected the port. Timed out means packets got no answer, often because of a drop rule or a powered-off machine.
The machine may still be installing. Wait until the panel shows Powered on with the address.
Yes. Reject rules send a refusal. Check ufw, firewalld or nftables for the SSH port.
Reboot from the panel first. If the bad setting persists, reinstall from the panel, which erases the disks.
Ubuntu 24.04 uses socket activation, so systemd holds the socket and starts sshd on demand.