21+ years in hosting · Jaipur, India · INR billing with 18% GST · 24/7 email support
Blog · WebJi® India

SSH Connection Refused on a VPS

Quick answer

Connection refused means the server answered with a TCP reset: the host is reachable but nothing is listening on that port. Check sshd, then the Port line in sshd_config, then UFW or iptables, then fail2ban. A timeout instead of a refusal means packets are dropped — a network problem.

For VPS owners locked out by a refused SSH connection, in the order the causes actually occur.

✓ In business since 2005
✓ INR + GST billing
✓ 24/7 Email Support — avg reply < 60 min
GuideWebJi®
knowledge
Read time
5 min
Sections
7
Updated
14 Nov 2026
Written by
WebJi® team

What "connection refused" actually means on a VPS

"Connection refused" means the server was reachable and answered with a TCP reset — something decided there is no service listening on the port you dialled. That is a narrower problem than it sounds, and separating it from the two errors people confuse it with saves the most time.

Three SSH errors and where to look first
MessageWhat happenedLook at first
Connection refusedHost answered with a reset; nothing is listening on the portsshd service, Port setting, local firewall, fail2ban
Connection timed outNo answer; packets dropped or the host is downIP address, provider security group, host status
Permission denied (publickey)SSH reached the daemon but authentication failedKey, username, sshd_config authentication rules

Refused is a service or port problem; timeout is a network or provider problem; permission denied is a credential problem. This guide works the first column, in the order the causes actually occur.

Check the address and the port before changing anything

Confirm the IP and the port first, because most refusals after a rebuild or migration are simply the old IP or an old port saved in the SSH client. Four checks, two minutes, no configuration touched.

  1. Ping the host: ping -c 4 YOUR.SERVER.IP. Some providers block ICMP, so a silent ping is not proof of a dead server.
  2. Test the port directly: nc -vz YOUR.SERVER.IP 22. A refusal here matches what SSH reports; an open result means the problem is authentication, not the network.
  3. Watch the negotiation: ssh -vvv user@YOUR.SERVER.IP prints the port it tried and where it stopped.
  4. Read the provider panel: some hosts expose SSH on a non-standard port for managed access — copy both IP and port from there.

On Windows, PuTTY shows the same "connection refused" for the same causes: fill Host Name with the IP, Port with the panel's port, and read the connection log before changing settings. If you have never generated a key pair for the machine, the SSH key guide for Ubuntu covers that side.

Is sshd running and listening?

Two commands answer this: one says whether the service is active, the other whether it is actually listening — and the second is the one that matters. A service can be "active" yet bound to nothing.

sudo systemctl status ssh
sudo ss -tlnp | grep -E ':22|:2222'
sudo journalctl -u ssh -n 50 --no-pager

A healthy output shows LISTEN on 0.0.0.0:22 or [::]:22 next to sshd. If the service is active but nothing listens, the daemon failed to bind: another process took the port, the config names a different Port, or ListenAddress points at an address the server no longer holds — the OpenSSH manual documents both directives with 22 as the Port default. On RHEL, AlmaLinux and Rocky the unit is sshd, not ssh: start and enable it with sudo systemctl enable --now sshd, then read the journal again if it exits immediately.

The firewall can refuse you from three places

A VPS can run three firewalls at once — UFW or firewalld inside the OS, raw iptables or nftables rules, and the provider's security group outside the machine — and a port open in one can still be closed in another. Check all three before assuming sshd is broken.

  • OS firewall: sudo ufw status verbose shows the Ubuntu rules; sudo ufw allow 22/tcp then sudo ufw reload opens the port.
  • Raw rules: sudo iptables -L -n --line-numbers — look for REJECT or DROP sitting above any ACCEPT for your port; order matters.
  • Provider firewall: the panel's security group needs its own inbound rule for TCP 22, or your custom port, ideally scoped to your IP.
  • Docker: Docker inserts its own iptables chains, so a container publishing a port can bypass UFW — which is why the rules look right and the port still refuses.

Do not start by flushing every rule. Add the ACCEPT rule you need, confirm the login works, and only then tidy the rest — a blind flush can expose services that were deliberately closed.

Wrong port, AllowUsers and fail2ban bans

Three configuration mistakes produce a refusal even when sshd is healthy: a changed Port, an AllowUsers list that excludes you, and a fail2ban ban on your IP. Work them in that order, and always keep your current session open while you restart the service.

  1. Read the active Port line in /etc/ssh/sshd_config; a commented #Port 22 means the default 22 still applies.
  2. Test before restarting: sudo sshd -t checks the config's validity ("test mode" in the sshd manual). A syntax error here is how a working server becomes unreachable.
  3. Restart safely: with one session still open, sudo systemctl restart ssh, then test from a second session — if the second fails, the first can undo the change.
  4. Check fail2ban: sudo fail2ban-client status sshd; if your IP is listed, sudo fail2ban-client set sshd unbanip YOUR.IP.
  5. Whitelist yourself: add your office or admin IP under ignoreip in /etc/fail2ban/jail.local so one typo cannot lock you out again.

If the panel shows a custom SSH port, the client needs ssh -p PORT user@IP — and the firewall needs that port, not 22.

Recovery from the provider console when SSH is already down

When no login works, stop editing blind and use the provider's VNC console, serial console or rescue mode, which reaches the machine without SSH. The journal almost always names the exact line that broke.

  1. Open the console from the VPS panel and log in as root with the provider password.
  2. Read the journal: journalctl -u ssh -n 100 --no-pager.
  3. Fix sshd_config, run sshd -t, then restart the service.
  4. In rescue mode, mount the disk read-write, edit the file from the mounted root, unmount, boot normally.
  5. Test from outside with nc -vz IP 22 before closing the console.

Take a snapshot before rescue-mode surgery if the panel offers one. The sudo user guide covers creating a second admin account — the cheapest insurance against a lockout.

Prevent the next SSH lockout

Most lockouts are self-inflicted during a hardening change, and four habits remove almost all of them. Keep a second admin user with sudo and a tested key; allow both the old and new SSH port for a week when you change ports; whitelist your admin IP in fail2ban and the provider firewall before tightening anything; and watch the port with an external uptime check so a closed port is an alert, not a 2 a.m. surprise.

If the server is a WebJi® VPS, the panel console and rescue options are part of the service, and support at support@webji.services can read the journal with you — email is answered 24/7 in Hindi and English, average first reply under 60 minutes. For host-level firewall policy on cPanel machines, the CSF firewall guide covers the ConfigServer side, and SSH two-factor authentication is the next hardening step once you are back in.

FAQ

Frequently asked questions

Why is my SSH connection refused?

The port you dialled has nothing accepting connections. In order of frequency: sshd is stopped, it listens on a different port after a config change, UFW or iptables rejects 22, the provider security group blocks it, or fail2ban banned your IP. Run the checks in that order.

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

Refused means the host answered with a TCP reset — it is reachable but nothing is listening on that port. Timed out means no answer at all, which points to a dropped packet, a wrong IP, a security group or a down host rather than a stopped service.

How do I check whether SSH is running?

Run systemctl status ssh on Ubuntu or Debian, or systemctl status sshd on RHEL-family systems. Then run ss -tlnp | grep :22 to see whether it is actually listening, and journalctl -u ssh -n 50 for the reason it stopped.

Can fail2ban lock me out of my VPS?

Yes. Repeated failed logins add your IP to the ban list and the connection is refused until the bantime expires. From the provider console run fail2ban-client status sshd to see the list, then fail2ban-client set sshd unbanip YOUR.IP, and add your IP to ignoreip so it does not repeat.

How do I fix SSH refused after a firewall change?

Get in through the provider console, run iptables -L -n and ufw status to find the rejecting rule, and add an ACCEPT rule for your port before removing anything. Do not flush every rule first — that can open the server wider than it was.

Last editorial update: 15 November 2026.

WebJi® since 2005

Ready to get started with WebJi®?

Join 12,000+ businesses across India and overseas. INR pricing, 18% GST shown before payment and 24/7 email support in Hindi and English — average first reply under 60 minutes.