ssh: connect to host 203.0.113.10 port 22: Connection refused means the TCP connection attempt received an active rejection before SSH authentication began. The most common reason is that nothing is listening at the address and port you tried. A firewall sending a TCP reset can produce the same symptom.
Start with the actual destination and TCP listener, not your password or key. This guide separates client-side checks from server-console checks and shows a reproducible Docker lab that distinguishes Connection refused from a timeout.
Lab provenance: the terminal captures below document the original isolated tests. The article was adapted to ShadeTerm on November 28, 2026; no new benchmark run is claimed.
1. What does SSH “Connection refused” mean?
Before SSH negotiates encryption, the operating system tries to establish a TCP connection. If the destination port is closed, the host commonly replies to the SYN packet with a TCP RST (reset); the client reports Connection refused (ECONNREFUSED on Linux). A firewall or intermediate device can also actively reject a TCP connection.
A refusal does not prove that the intended SSH server answered. You may have the wrong address, a stale DNS record or a port-forwarding rule to a different machine. Check the address printed in ssh -vv before editing SSH server settings.
| Client error | What it suggests | Next test |
|---|---|---|
Connection refused | Active TCP refusal / reset, commonly no listener or explicit firewall reject. | Check destination IP, server listener and firewall rule. |
Connection timed out | No response to TCP connection attempts in time. | Check DROP rules, reachability and network path. Timeout guide. |
No route to host | Reachability failure or returned ICMP unreachable, not always a missing route. | Investigate routes and ICMP rejects. |
Permission denied (publickey) | TCP and SSH negotiation got far enough to attempt authentication. | Inspect keys and account policy. |
Incorrect SSH passwords and keys do not normally produce this TCP error. An absent SSH client produces a missing-command error instead. These distinctions prevent unnecessary reinstallations and credential changes.
2. The five-check diagnostic path
- 1Confirm the target. Match the IP or DNS result and SSH port against the server console or hosting dashboard. SSH may not use port 22.
- 2Reproduce at TCP level.
nc -vz -w 5 HOST PORTon Linux/macOS, orTest-NetConnection HOST -Port PORTon Windows. - 3Find the listener on the server. Use
ss -ltnpwith the actual port, not justsystemctl status. - 4Inspect the service or socket and firewall. Check OpenSSH's effective configuration, Ubuntu's
ssh.socketand any explicit TCP-reset rules. - 5Change one thing, retest exactly. Re-run the same TCP probe before interpreting SSH authentication messages.
Do these checks from the correct machine. ssh localhost on your laptop tests the laptop, not the remote server. A local test is useful only when executed on the remote server itself via console.
3. Check the host, address and port from your client
OpenSSH's debug output identifies which resolved IP and port it attempted. If you use an SSH config alias, ssh -G also shows command-line and config-file values before connecting:
ssh -G my-server | grep -E '^(hostname|user|port|addressfamily) '
ssh -vv -o ConnectTimeout=5 my-server
nc -vz -w 5 server.example.com 22
Windows PowerShell has equivalent checks:
ssh -G my-server | Select-String '^(hostname|user|port|addressfamily) '
Resolve-DnsName server.example.com
Test-NetConnection server.example.com -Port 22 -InformationLevel Detailed
The TcpTestSucceeded value says whether the TCP probe connected; it does not on its own distinguish a reset from a timeout. For that, compare it with OpenSSH's exact error. If a host has both IPv4 and IPv6 addresses, test ssh -4 versus ssh -6 rather than assuming the same network path applies.
A successful ping tells you only that ICMP echo works. Ping can succeed while TCP port 22 refuses connections; conversely, ping can be blocked while SSH still works.
4. Our Docker test: Connection refused with no SSH listener
We used two isolated Ubuntu 24.04 Docker containers on a user-defined bridge network: a test client and an OpenSSH server container. For the first run, OpenSSH was installed but sshd was not started. The client could still reach the server over ICMP, while nothing listened on TCP port 22.
Our first capture documents the useful combination of observations: the server answers ping, ss shows no port-22 listener, and independent nc and ssh probes report Connection refused. The hostname identifies a disposable Docker container rather than a public server.
# Test from the lab client
nc -vz -w 3 sshflow-refused-server 22
ssh -o ConnectTimeout=3 root@sshflow-refused-server
# Inspect on the lab server
ss -ltn '( sport = :22 )'

What this proves: a reachable host can reject a TCP connection when no service is listening. It does not establish that a real-world firewall is correctly configured or that your own VPS has the same cause.
5. Our Docker test: starting sshd restores TCP/22
For the second run, we kept the same containers and destination port, started sshd, checked the listener with ss, and repeated the same Netcat probe. The resulting capture shows the listener and successful TCP connection. The changed condition was the availability of the SSH service, not a different host or port.
# Inside the disposable test server
mkdir -p /run/sshd
/usr/sbin/sshd
ss -ltnp '( sport = :22 )'
# From the test client
nc -vz -w 3 sshflow-refused-server 22

Observed before-and-after behavior
| Condition | Port 22 / SSH observation | What changed? |
|---|---|---|
| No sshd listener | ss shows no port 22 socket; nc and ssh report Connection refused. | OpenSSH is installed but not running. |
| sshd started | ss shows LISTEN on port 22; Netcat establishes a TCP connection. | Only the server-side listener is restored. |
A subsequent SSH error such as Permission denied (publickey) is progress: network connectivity and the SSH handshake have advanced to authentication. Do not confuse this with an unsuccessful TCP repair.
What the comparison establishes: in this controlled environment, restoring the listening daemon removes the TCP refusal. It does not imply that restarting SSH is the correct fix when a different server is refusing connections because of a firewall, an address mismatch or a broken forwarding rule.
6. Check the OpenSSH service — and Ubuntu's ssh.socket
Use the host's console or another authorized management path. On Debian and Ubuntu, the unit is commonly ssh.service; on Fedora, RHEL and Rocky Linux, sshd.service. First check the listening port, then the service details and logs.
# On a Debian/Ubuntu server
sudo ss -ltnp '( sport = :22 )'
systemctl status ssh.service ssh.socket --no-pager
sudo journalctl -u ssh.service -u ssh.socket -n 50 --no-pager
Ubuntu 24.04 and newer releases need special care. On a system using systemd socket activation, ssh.socket may listen on port 22 even when ssh.service appears inactive before a connection. The listener check is therefore stronger evidence than the service status alone.
When the package is missing, install it from the local/provider console with sudo apt install openssh-server. If the socket is deliberately disabled and SSH is not listening, check the unit's configuration before enabling it; on standard Ubuntu installations using socket activation, sudo systemctl enable --now ssh.socket is a possible remedy. On older service-based installations the relevant unit may instead be ssh.service.
Ubuntu 24.04 custom-port trap: if you change Port or ListenAddress in sshd_config, a socket-activated installation may require a systemd generator refresh before the effective listener changes. After validating the configuration, and only with provider console or rollback access, the relevant sequence can be systemctl daemon-reload followed by systemctl restart ssh.socket. Do not restart a remote SSH socket while it is your only working management path. See the Ubuntu package-team explanation.
For Fedora/RHEL-family servers, inspect systemctl status sshd.service and its logs. For Ubuntu details see our Ubuntu SSH setup guide.
7. Verify the actual listening port and interface
A running SSH process may listen on a different port, only on loopback, or on a specific interface. Unlike grep ssh, a port-based ss query will also find a socket owned by systemd.
# All TCP listeners, regardless of process name
sudo ss -ltnp
# OpenSSH daemon's parsed configuration
sudo sshd -t
sudo sshd -T | grep -E '^(port|listenaddress|addressfamily) '
| Observed listener | What it means |
|---|---|
0.0.0.0:22 | IPv4 listener bound to all local IPv4 addresses. |
127.0.0.1:22 | Only local IPv4 loopback clients can reach that listener. |
0.0.0.0:2222 | SSH may be on a custom port; use ssh -p 2222. |
| No TCP listener | Inspect package, service/socket and logs. A firewall rule cannot create a missing listener. |
sshd -T reports the daemon's parsed configuration; the live listening socket can differ, especially when ssh.socket owns the port. Also examine /etc/ssh/sshd_config.d/ and any service/socket overrides before changing settings. Run sshd -t to validate any proposed configuration update before a careful reload.
8. Could a firewall be actively refusing SSH?
Yes. A firewall using REJECT --reject-with tcp-reset can make a reachable, listening SSH port look closed to the client. By contrast, a silent DROP often results in Connection timed out. A host-unreachable ICMP rejection can produce No route to host instead. These are different mechanisms, so don't infer a specific firewall rule from the word “refused” alone.
# Inspect; do not change remote-server rules blindly
sudo nft list ruleset
sudo iptables -S
sudo ufw status verbose
# Only if your server runs firewalld:
sudo firewall-cmd --list-all
Cloud security groups and network ACLs are another layer. Many cloud controls silently drop denied traffic rather than returning a TCP reset, so the exact message alone rarely identifies which layer blocked it. If your server is reachable through a provider console, verify the actual source IP, destination port and interface.
Do not purge/reinstall OpenSSH as a first fix. That approach appears in older community examples, but it can change server configuration and create additional risk without proving the original fault. Start with the evidence: socket, logs and scoped firewall rules.
9. Our firewall test: REJECT versus DROP
We also tested a separate failure mode while the SSH daemon was still listening: a firewall rejecting TCP/22. In the disposable container with NET_ADMIN, we inserted a temporary tcp-reset REJECT rule, compared its behavior with a silent DROP rule, and removed each rule after the probe. The server and destination port remained unchanged.
# Inside the disposable server container ONLY (not a remote VPS)
iptables -I INPUT 1 -p tcp --dport 22 -j REJECT --reject-with tcp-reset
# Probe from the other container: nc -vz -w 3 SERVER 22
iptables -D INPUT -p tcp --dport 22 -j REJECT --reject-with tcp-reset
iptables -I INPUT 1 -p tcp --dport 22 -j DROP
# Repeat the same probe with a finite timeout
iptables -D INPUT -p tcp --dport 22 -j DROP

| Test condition | Expected TCP outcome | Reason |
|---|---|---|
REJECT --reject-with tcp-reset | Connection refused | Explicit TCP reset rejects the SYN. |
DROP | Connection times out | No TCP response; the client retries until its limit. |
| Temporary rule removed | TCP/22 connects | Listener remains active and filter no longer blocks it. |
Interpretation: the reset-based rejection produces the same client-visible refusal as a closed port, despite an active SSH listener. A silent DROP instead allows the TCP connection attempt to time out. Our test demonstrates these mechanisms in one Docker environment; other firewalls, kernels and network middleboxes may return different errors.
10. Wrong host, DNS, NAT and IPv4/IPv6
A refused connection does not necessarily come from the server you meant to reach. Inspect OpenSSH's Connecting to ... [IP] port ... line and compare it with your provider's console. When a DNS record is stale or an address was reassigned, a different host may be returning the reset.
# Linux: confirm name resolution
getent ahosts server.example.com
# Separate IPv4 and IPv6 path tests
ssh -4 -o ConnectTimeout=5 [email protected]
ssh -6 -o ConnectTimeout=5 [email protected]
# Explicit non-default SSH port
ssh -p 2222 [email protected]
For a VM behind a NAT router, confirm the external port forwards to the correct internal IP and internal port. If the forward points to another host, the rejected connection may be real but misleading. A private IP cannot generally be reached from outside its network without an authorized VPN, router mapping or bastion.
Check address changes after VPS rebuilds, IPv6-only versus IPv4-only listeners, and whether a VPN changes routing or name resolution. Avoid treating every refusal as a firewall issue.
11. Docker containers and virtual machines
In Docker, three addresses can be involved: the address inside the container, the Docker bridge address and the host's published port. A working listener inside a container does not automatically expose SSH to the host or another network.
docker ps --format 'table {{.Names}} {{.Ports}}'
docker port CONTAINER_NAME
docker exec CONTAINER_NAME ss -ltnp
If a new test container should accept connections from the Docker host, use an explicit port publication at creation (for example -p 127.0.0.1:2222:22 for local-only access). Do not publish a root-accessible SSH service to the public internet merely for testing.
For virtual machines, confirm bridged versus NAT mode, host-only networks, forwarding rules and the guest's IP. Test the host/guest TCP connection independently before assuming the OpenSSH configuration is broken.
12. Raspberry Pi: check whether SSH was enabled
Raspberry Pi OS disables the SSH server by default. A newly imaged device may answer ping but refuse port 22 until you enable remote access. Raspberry Pi's official remote-access guide describes enabling SSH during imaging under Customisation → Remote Access, from Control Centre, or via raspi-config.
For a headless setup, configure an actual user and SSH authentication method during imaging. Do not rely on old tutorials that assume a default pi/raspberry account. After enabling SSH, check the Pi's actual LAN IP and the same TCP port from your client.
13. Frequently asked questions
Why does SSH say Connection refused when ping works?
Ping uses ICMP echo, while SSH usually connects over TCP port 22. A device can answer ICMP while having no process listening on TCP/22, or while actively rejecting that port with a firewall.
Does Connection refused mean my SSH password is wrong?
No. The TCP connection was rejected before SSH authentication. Check the host, port and server listener first; only inspect passwords and keys once you reach authentication.
What if systemctl says ssh.service is inactive on Ubuntu 24.04?
Check ssh.socket and the actual port-22 listener. Socket activation may be working even before ssh.service starts.
Will reinstalling openssh-server fix the error?
It may repair a missing or corrupted package in some cases, but an immediate purge is not a safe generic fix. Confirm the package state, systemd units, listener, configuration syntax and logs first.
Does Connection refused mean the firewall is blocking port 22?
Not necessarily. An absent listener and an active TCP-reset firewall rule can look similar from the client. Use server-side ss, unit status and the effective firewall rules to distinguish them.
Sources and test methodology
Our method combines primary OpenSSH, Ubuntu and Linux firewall documentation with three screenshots from a two-container Ubuntu 24.04 Docker investigation. We compared a stopped SSH listener with a running one, then held the listener constant while changing a targeted firewall rule. Each capture shows terminal observations instead of a simulated error dialog. Scope: these are reproducible laboratory failure modes, not evidence that every production Connection refused incident has the same cause.
- OpenSSH sshd_config(5) — effective port, ListenAddress and server settings.
- Linux iptables-extensions(8) — how TCP-reset REJECT differs from silently dropping packets.
- Ubuntu Server: OpenSSH — installation, SSH server settings and verification.
- Ubuntu package-team socket note — reloading a port configuration on Ubuntu 24.04.
- DigitalOcean SSH troubleshooting — host/port, service and firewall diagnosis.
- Ask Ubuntu — a real case with an allowed firewall port but no SSH listener.
- Linuxize — service/socket, listener and firewall checks.
- SiteGround — hosting-provider concerns and non-default ports (not all listed causes correspond specifically to TCP refusal).
- Geek Culture / Medium — example of repair by reinstallation; not a recommended universal first step.
- Raspberry Pi documentation — enabling the SSH server.
Conclusion
When SSH immediately says Connection refused, verify the exact destination IP and TCP port, then check whether anything is listening there. A stopped service, a mismatched bind address and an explicit firewall TCP reset can produce similar client symptoms but require different repairs. On Ubuntu 24.04, check ssh.socket before declaring the service broken.
Once the server is reachable, ShadeTerm brings terminals, SFTP, files, code and monitoring into one workspace. It cannot override a broken TCP path or a deliberate firewall rejection.