How to Fix SSH Connection Refused on a VPS in 2026

0
(0)

SSH connection refused means your client reached the VPS address, tried to open the SSH port, and the other side rejected the TCP handshake. In practice, nothing is accepting connections on that port, or a firewall is sending an explicit reject. It is not a wrong password, and it is not the same as a hang that never answers.

This walkthrough shows how to tell refused from timeout and permission errors, then how to check the IP, the port, the SSH service, the listen address and the firewall. The commands assume a Linux VPS you can still reach through the provider’s console or a rescue environment.

Connection refused vs timeout vs permission denied

What you see What it usually means Where to look first
Connection refused The host responded, but nothing accepted the TCP session on that port, or a filter rejected it sshd status, listen port, listen address, REJECT firewall rules
Connection timed out Packets are being dropped or never arriving Provider firewall, security group, dropped INPUT rules, wrong network path
Permission denied or authentication failed SSH is running and reachable; the login itself failed Username, key, authorized_keys, PasswordAuthentication, account lock
No route to host or network unreachable Your machine cannot find a path to the VPS address Local routing, VPN, typo in the IP, instance not provisioned

Fixing the wrong class of error wastes time. If SSH already asks for a key or a password, the connection is working and this article is not the problem. If the client sits there until it times out, start with path and drop rules, not with systemctl start ssh alone.

Step 1: confirm the address, port and error

From your own computer, run a verbose SSH attempt and read the last lines carefully:

ssh -vvv -p 22 USER@SERVER_IP

Replace 22 if you changed the SSH port. A refused connection often shows up as connect to ... port 22: Connection refused before any SSH protocol banner. Note the exact IP and port the client used. A typo, an old IP after a rebuild, or an IPv6 address when you meant IPv4 is enough to send you to the wrong machine.

See also  IPv4 vs IPv6 on a VPS in 2026: Dual-Stack Setup and Compatibility

Then test the port without SSH authentication:

nc -vz SERVER_IP 22
# or
python3 -c "import socket; s=socket.create_connection(('SERVER_IP',22),5); print('open'); s.close()"

If you want a broader method for checking a TCP port, use the port ping guide. A refused result here still points at the listener or a reject rule. A timeout points at a drop rule or a network path problem.

Also confirm the VPS is actually running in the provider panel. A powered-off instance can produce different errors depending on whether the old IP still has something in front of it. After a reinstall, the public IP may have changed.

Step 2: get a console session if SSH is down

You cannot repair sshd through a connection that never opens. Use the provider’s web console, VNC, serial console or rescue mode. Keep that session open while you change SSH or firewall rules so a typo does not lock you out completely.

If even the console is unavailable, the next step is a support ticket with the IP, region, and a note that SSH is refused from your public IP. Do not start changing firewalls blindly from a second VPS until you know which host you are editing.

Step 3: check whether sshd is running

On Ubuntu and Debian, the service name is usually ssh. On AlmaLinux, Rocky Linux and other RHEL-like images, it is usually sshd:

systemctl status ssh --no-pager
systemctl status sshd --no-pager
ss -ltnp | grep -E 'sshd|:22|:2222'

If the unit is inactive or failed, start and enable it, then read the logs:

sudo systemctl enable --now ssh
# or: sudo systemctl enable --now sshd
sudo journalctl -u ssh -u sshd -e --no-pager

A failed start is often a bad sshd_config line, a missing host key, or a port already in use. Test the configuration before you restart again:

sudo sshd -t
sudo sshd -T | grep -E '^(port|listenaddress|permitrootlogin|passwordauthentication) '

sshd -t must succeed before you rely on a restart. If host keys are missing after a broken cloud-init run, regenerate them with the distribution’s official method, for example sudo ssh-keygen -A on many OpenSSH packages, then start the service again.

Step 4: confirm the listen port and address

Connection refused is common after someone changes the SSH port in /etc/ssh/sshd_config or a drop-in under /etc/ssh/sshd_config.d/ and then keeps connecting to 22. It also happens when sshd is bound only to localhost or only to an IPv6 address.

Check the effective configuration, not just the first file you open:

sudo sshd -T | grep -E '^(port|listenaddress) '
sudo ss -ltnp | grep ssh

You want a listen line on 0.0.0.0:PORT, [::]:PORT, or the VPS public address. A line that only shows 127.0.0.1:22 explains a refused connection from the internet: the service is running, but only for local clients.

See also  Shared Hosting vs VPS in 2026: When Should You Upgrade?

If you did change the port, allow that port on every firewall before you restart sshd, and test it from a second terminal. The VPS security guide covers the safer order for SSH changes: keep the current session open, prove a new login works, then close the old one.

Step 5: inspect host and provider firewalls

A firewall can refuse a connection (REJECT) or silently drop it (DROP). REJECT often looks like “connection refused.” DROP looks like a timeout. Check both the host firewall and any provider firewall or security group in the control panel.

On Ubuntu and many Debian images:

sudo ufw status verbose
sudo nft list ruleset
sudo iptables -L -n -v

On AlmaLinux, Rocky Linux and Fedora:

sudo firewall-cmd --list-all
sudo nft list ruleset

If UFW is active and does not allow your SSH port, allow it before you do anything else:

sudo ufw allow OpenSSH
# or, for a custom port:
sudo ufw allow 2222/tcp
sudo ufw reload
sudo ufw status verbose

Provider panels sometimes have a separate network ACL that is empty or that only allows HTTP. Opening port 22 on the VPS does nothing if the upstream firewall still rejects it. After a rebuild, those panel rules may not follow the new instance automatically.

fail2ban and similar tools can also ban your IP. A ban that uses REJECT will look like connection refused; a ban that uses DROP will look like a timeout. If you have console access:

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

Only unban an address you recognize. If you recently changed office or VPN IPs, the old address may still be listed.

Step 6: check systemd socket activation

Some Ubuntu Server images start SSH through ssh.socket rather than a service that is already listening. If the socket unit is disabled, masked, or set to a different port than the one you are calling, the result is a refused connection even though the ssh package is installed.

Check both units:

systemctl status ssh.socket ssh.service --no-pager
systemctl is-enabled ssh.socket ssh.service
sudo systemctl cat ssh.socket

If the socket unit is the one that should accept connections, enable it and confirm the listening port matches your SSH client. Do not enable both a conflicting socket and a service that try to bind the same port. After a change, run sudo ss -ltnp | grep ssh again and test from your laptop before you close the console.

Step 7: rule out IPv6, local networks and stale keys

If the VPS has IPv6 and your client prefers it, SSH may be hitting an address that is assigned in DNS but not listening. Force one protocol while you test:

ssh -4 -vvv -p 22 USER@SERVER_IP
ssh -6 -vvv -p 22 USER@SERVER_IP

From a restrictive office network or a hotel Wi-Fi, outbound port 22 may be blocked. That often times out rather than refused, but try a phone hotspot or a different network before you rebuild the server. A second VPS in the same region is also a useful probe: if that box can connect and your laptop cannot, the problem is on the client path.

See also  How to Migrate a Website to a VPS in 2026: DNS, rsync and Cutover

Stale known_hosts entries produce a host key warning, not connection refused. Do not delete host keys on the server to “fix” a refused connection. That warning is a different issue.

Step 8: collect evidence before you rebuild

A rebuild fixes a broken sshd only by throwing the instance away. Take a snapshot if the provider offers one, then capture a short evidence bundle from the console:

hostnamectl
ip addr
systemctl status ssh sshd --no-pager
sudo ss -ltnp
sudo sshd -T | grep -E '^(port|listenaddress) '
sudo ufw status verbose 2>/dev/null
sudo journalctl -u ssh -u sshd --since today --no-pager

If the service is healthy and the port is open on the host, the remaining work is almost always on the provider firewall or the IP you are calling. The VPS setup guide has a short connection checklist, and the Linux monitoring guide helps you confirm the instance itself is up while you debug the path to it.

Once SSH works again, add the usual account and key hardening rather than leaving password logins exposed. If you still need to finish a new server build, return to the setup guide or the Linux VPS website hosting guide after access is stable.

Frequently asked questions

Does connection refused mean my VPS was hacked?

No. The most common causes are a stopped sshd service, a port mismatch, a listen address bound to localhost, or a firewall REJECT rule. Treat it as a configuration or path problem first. Unusual logins or unexpected processes are a separate investigation once you have console access.

Why did SSH work yesterday and refuse today?

Typical triggers are a reboot that did not start sshd, a firewall change, a fail2ban ban, a provider network rule, or a new public IP after a rebuild or a plan change. Compare the IP in the panel with the IP in your SSH command before you edit configuration files.

Should I change the SSH port to fix connection refused?

Not as the first move. Changing the port without updating every firewall and your SSH client will produce exactly this error. Restore a working listener on a known port first, then change the port only if you still want that extra filter and you can test a second login first.

Can I test this from Windows?

Yes. Current Windows versions include OpenSSH. Run ssh -vvv user@server in PowerShell or Windows Terminal. PuTTY shows “Connection refused” in a dialog for the same TCP failure. The server-side checks in this guide still happen on the Linux VPS console.

What if only one of my computers is refused?

That usually points to a client-side firewall, a local VPN, or a fail2ban ban of that computer’s public IP. Compare ssh -vvv from the working machine and the failing one, and check the source IP the server sees if you have console or log access.

Sources

Was this guide helpful?

Rate this guide from 1 to 5 stars.

Average rating: 0 / 5. Ratings: 0

No ratings yet. Be the first to rate this guide.

Leave a Comment