>_ SSHDock
FeaturesHow it worksBlogGuidesAbout
Launch Terminal
Back to Journal

SSH connection refused: what it means and how to fix it

AH
Ayan Hussain
Mar 19, 2026 · 6 min read

On this page

  • The difference between refused and timed out
  • Step 1: Check cloud firewall rules
  • Step 2: Check if SSH is running on the server
  • Step 3: Check if SSH is on a non-standard port
  • Step 4: Check the OS-level firewall
  • Step 5: Verify you are connecting to the right IP
  • Step 6: Check if the server just needs more time
  • Debugging with verbose output
  • Common questions

ssh: connect to host port 22: Connection refused is the kind of error that looks alarming but usually has a straightforward explanation. The server actively rejected your connection request. That is different from a timeout, which means the server did not respond at all.

"Connection refused" specifically means your network packet reached the destination IP address, but the server sent back a TCP RST (reset) packet instead of accepting the connection. Nothing is listening on that port, or something is actively blocking it.

Here is how to find and fix the actual cause.

The difference between refused and timed out

Before diagnosing, it helps to know what each error actually means.

"Connection refused" means your computer reached the server's IP and the server responded, but said no. The server is reachable and alive, but SSH is not accepting connections on that port. This is usually a software problem (SSH not running, wrong port, firewall rule that rejects instead of drops).

"Connection timed out" means your computer sent packets and heard nothing back. The server did not respond at all. This is usually a network problem (firewall dropping packets silently, wrong IP, server completely offline).

The fix strategies are different for each, so knowing which one you have matters.

Step 1: Check cloud firewall rules

If you are on AWS, DigitalOcean, Google Cloud, or any other cloud provider, start here. Cloud firewall rules sit entirely outside the operating system. A perfectly configured Linux server with the port blocked at the cloud level will still refuse connections. The server has no idea the connection was even attempted.

AWS EC2: In the EC2 console, click your instance, go to the Security tab, and look at the attached security group. You need an inbound rule allowing TCP port 22 from your IP address (or 0.0.0.0/0 if you want to allow all IPs, though restricting to your IP is better).

DigitalOcean: Under Networking, check Cloud Firewalls for your Droplet. The rule needs TCP port 22 inbound.

Google Cloud: In VPC Network, check Firewall Rules for an ingress rule on tcp:22 that applies to your instance. Check that the target tag on the firewall rule matches a tag on your instance.

Hetzner / Vultr / other providers: Check the network firewall or security group equivalent in the control panel.

If you need to find your current public IP to create an accurate firewall rule:

curl ifconfig.me

Step 2: Check if SSH is running on the server

If the cloud firewall is open and the connection is still refused, SSH itself might not be running. If you have another way into the server (cloud web console, VNC, physical access), log in and check:

sudo systemctl status sshd

If the output shows inactive (dead) or failed, start it:

sudo systemctl start sshd
sudo systemctl enable sshd

enable makes the service start automatically on reboot. If it was not enabled and the server rebooted recently, that could explain a working server that suddenly became unreachable.

If systemctl status sshd shows an error, look at the logs:

sudo journalctl -u sshd --since "1 hour ago"

Common reasons SSH fails to start: a syntax error in /etc/ssh/sshd_config after a configuration change, missing host keys (which can happen on minimal Docker images), or a port conflict if something else is already using port 22.

To check for a sshd_config syntax error:

sudo sshd -t

This validates the config file without actually starting the daemon. It will print the error and line number if there is a problem.

Step 3: Check if SSH is on a non-standard port

Many administrators move SSH off port 22 to reduce automated scan noise. If SSH is running but port 22 is still being refused, check whether it is listening on a different port:

sudo ss -tlnp | grep ssh

If you see it on port 2222 or something else, connect by specifying the port:

ssh -p 2222 user@host

The server's sshd_config will have a line like Port 2222 if this is the case. You can also check /etc/ssh/sshd_config directly if you have access.

If you use SSHDock, change the port number in the connection form.

Step 4: Check the OS-level firewall

Even if the cloud firewall is open, the operating system may have its own firewall rules blocking port 22.

On Ubuntu and Debian, check UFW (Uncomplicated Firewall):

sudo ufw status verbose

If UFW is active and port 22 is not listed as allowed, add the rule:

sudo ufw allow 22/tcp

If you changed SSH to a non-standard port:

sudo ufw allow 2222/tcp

On RHEL, CentOS, and AlmaLinux, check firewalld:

sudo firewall-cmd --list-all

Look for ssh in the services list. If it is missing:

sudo firewall-cmd --add-service=ssh --permanent
sudo firewall-cmd --reload

On older systems that use iptables directly:

sudo iptables -L -n | grep 22

Step 5: Verify you are connecting to the right IP

This sounds obvious but it catches people regularly. If you have multiple servers, or if DNS records are stale, you might be hitting the wrong machine.

Check that the IP you are connecting to matches the server in your cloud console:

ping yourdomain.com

Compare the IP in the ping output to the IP shown in your cloud control panel. DNS TTLs can keep old records cached for hours after you update them.

Step 6: Check if the server just needs more time

If you just launched a new server, give it 2 to 3 minutes. Cloud instances take time to fully boot, generate SSH host keys, and start the daemon. Connecting within 30 seconds of launch sometimes catches the instance before SSH is ready.

Debugging with verbose output

If none of the above resolves it and you can get some kind of connection attempt through, verbose SSH output shows exactly where things fail:

ssh -vvv user@host

With three -v flags, SSH prints every step: DNS resolution, TCP connection attempt, protocol negotiation, key exchange, and authentication. Look for where the output stops or shows an error.

The server logs are also useful. On Ubuntu/Debian:

sudo tail -f /var/log/auth.log

On RHEL/CentOS:

sudo tail -f /var/log/secure

If you can reach the server through a cloud console and watch these logs while making a connection attempt, you can often see exactly what the server saw and why it refused.

Common questions

Is connection refused the same as permission denied?

No. Connection refused happens at the network level before authentication starts. Permission denied happens after you have connected and SSH is refusing your credentials (wrong key, wrong password, account locked). If you are getting connection refused, your authentication details are not even being checked yet.

Can a firewall cause connection refused instead of timeout?

It depends on the firewall rule type. A "drop" rule silently discards the packet (causing a timeout). A "reject" rule sends back an explicit error (causing connection refused). Both are possible from firewalls. When you see connection refused from a cloud server you just set up, it is more likely that SSH is not running or the port is wrong than a reject-style firewall rule.

What if I locked myself out by disabling password auth before key auth was working?

Use the cloud provider's web console to access the instance directly, bypassing SSH. AWS calls this "EC2 Instance Connect" or "Session Manager." DigitalOcean and others have a web-based console in the control panel. From there, you can fix /etc/ssh/sshd_config and restart the daemon.

AH
Written by
Ayan Hussain

Full-Stack Developer and creator of SSHDock. Ayan builds browser-based developer tools and writes about SSH security, Linux server management, and modern web engineering.

About meGitHub

Keep reading

Oct 6, 2026

How to Fix 'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!'

Why you get the scary StrictHostKeyChecking warning in SSH, what a man-in-the-middle attack looks like, and how to safely clear out old known_hosts entries.

Oct 6, 2026

How to Use SSH Without Administrator Privileges on Windows

A practical guide to getting a working SSH client on restricted Windows machines, school computers, and corporate laptops when you don't have local admin rights.

Oct 6, 2026

MobaXterm vs PuTTY vs SSHDock: Choosing the Right Windows SSH Client

A practical comparison of the three major paradigms for SSH on Windows: barebones protocol tools (PuTTY), heavy "all-in-one" suites (MobaXterm), and modern web-native terminals (SSHDock).

SSHDOCK

Full terminal in your browser. Local credential storage, jump host tunneling, live CPU/memory/disk metrics, and a mobile soft-key bar. Free to use. Built by developers, for developers.

© 2026 SSHDock

GitHub (@ayanhackspro)
App
Launch TerminalFeaturesHow it worksBlog & TutorialsChangelogGuides
Cloud Guides
AWS EC2DigitalOcean DropletGoogle Cloud Compute EngineMicrosoft Azure Virtual MachineLinode Compute InstanceVultr Cloud Compute
Legal & Contact
Privacy PolicyTerms of ServiceDisclaimerContact UsAbout Creator
Modern, minimal browser SSH client
TerminalSitemap