SSH: “Connection refused” on port 22
Server setup troubleshooting
Updated
What you see
The command fails immediately, without a wait:
ssh: connect to host 203.0.113.24 port 22: Connection refused
What it means
Your request reached the server, and it said no: nothing is listening on that port, or a firewall rule rejects it. That's useful — the address and the network are fine, and what's left is the SSH service or the port.
Quick fix
Open your host's web console, check that the SSH service is running, and note which port it uses. Then connect with that port.
Causes and how to fix them
1. SSH isn't running or isn't installed
Some minimal images don't start it, and it can stop after a failed update. In the web console, check it and start it. The service is called ssh on Debian and Ubuntu, and sshd on most other systems:
sudo systemctl status ssh sudo systemctl enable --now ssh
2. SSH is listening on a different port
If the port was changed, port 22 refuses connections. See which ports SSH uses, then connect to that one:
sudo ss -tlnp | grep ssh ssh -p 2222 root@203.0.113.24
3. A firewall rejects the port
A firewall that rejects rather than silently drops answers with “refused”. Check the server's own firewall, and your host's, for a rule that allows TCP 22:
sudo ufw status sudo ufw allow 22/tcp
4. The server is still booting or being rebuilt
Right after creating or reinstalling a server, SSH starts a little later than the network does. Wait a minute and try again.
Using Nullsify?
Nullsify connects to the SSH port you give when adding the server, which is 22 unless you change it. If you moved SSH to another port, enter that port in the dialog, and make sure the host's firewall lets Nullsify's servers in.
Free for 1 server. Bring your own VPS — Nullsify configures WireGuard, AmneziaWG or VLESS on it for you.
Related problems
- “Connection timed out” Server setup
- “Permission denied (publickey)” Server setup
- “Remote host identification has changed” Server setup