ssh: connect to host port 22: Connection refused

Your client reached the host’s IP, but nothing accepted TCP on that port. Connection refused is an active rejection — usually sshd is down, listening elsewhere, or you aimed at the wrong port.

How it shows up

ssh: connect to host 203.0.113.10 port 22: Connection refused
ssh: connect to host example.com port 22: Connection refused
kex_exchange_identification: Connection closed by remote host
  (sometimes after a refused/retry path)

Verbose mode stops before any key exchange banners from sshd:

ssh -vvv [email protected]
# … look for "connect to address … port 22: Connection refused"

Refused vs timed out vs auth failures

MessageLayerTypical cause
Connection refused (port 22)TCPHost up; nothing listening on that port / sshd stopped / wrong port
Connection timed outTCPFirewall drop, blackhole route, host down, security group with no reply
Permission denied (publickey)SSH authsshd is up; keys/users/sshd_config rejected you
REMOTE HOST IDENTIFICATION HAS CHANGEDHost keysshd answered; known_hosts conflict
localhost refused to connectLocal TCPSame idea for a local app port, not necessarily SSH

Rule of thumb: timeout ≈ “silence / drop”. Refused ≈ “something said no on that port”. Auth errors ≈ “SSH protocol started”.

Frequent real causes

Diagnose

# From your laptop: does anything accept 22?
nc -vz example.com 22
# or
curl -v telnet://example.com:22

# On the server (console / VNC / provider serial):
sudo systemctl status ssh   # Debian/Ubuntu
sudo systemctl status sshd  # RHEL/Fedora/CentOS
sudo ss -ltnp | grep -E ':22|:2222'
sudo journalctl -u ssh -n 50 --no-pager

# Configured port?
grep -E '^(Port|ListenAddress)' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* 2>/dev/null

If ss -ltnp shows sshd on :2222 only, connect with ssh -p 2222 user@host. Port numbers as plain integers are easy to mix up — the number base converter is handy when a panel shows hex.

Fix checklist

  1. Confirm refused vs timeout — if it always times out, follow Connection timed out (security groups, ufw, iptables DROP) instead of restarting sshd blindly.
  2. Start sshd — sudo systemctl start ssh (or sshd) and enable it for boot; watch status for config errors.
  3. Match the port — client -p / Port must equal sshd’s Port; update cloud “SSH port” firewall rules to match.
  4. Listen address — ensure sshd listens on the interface you reach (or 0.0.0.0 / :: as appropriate).
  5. Right host — resolve DNS, compare inventory; a refused public IP may simply not be the VM you think.
  6. After TCP works — next failures are usually keys (publickey) or host key warnings (host key verification failed).
# Once listening, a banner should appear:
ssh -v -p 22 [email protected]
# look for "Remote protocol version" / offer of host keys

Related

What port 22 and other common ports are for · ssh Connection timed out port 22 · Permission denied (publickey) · SSH host key verification failed · SSH key permissions are too open · localhost refused to connect · ECONNREFUSED ::1 · ERR_NAME_NOT_RESOLVED · Anvil HTTP status

Questions

What does ssh Connection refused port 22 mean?

The client reached the host’s address, but nothing accepted TCP on port 22 (or the port you requested). Usually sshd is down or listening on another port.

How is Connection refused different from Connection timed out?

Refused means the host answered with a TCP reset/reject on that port. Timed out means no useful reply — often a firewall drop, wrong route, or host unreachable.

How is this different from Permission denied (publickey)?

Permission denied means sshd is running and speaking SSH; your keys or user were rejected. Connection refused never gets that far.

sshd is installed — why still refused?

The service may be stopped, failed to start after a config typo, or bound to a different Port / ListenAddress than the one you dial.

How do I connect if SSH is on port 2222?

ssh -p 2222 user@host, or set Port 2222 in ~/.ssh/config for that Host. Open the same port on the cloud firewall.

Can a firewall cause Connection refused?

Yes if the policy is REJECT. Many cloud security groups DROP instead, which looks like a timeout. Check both.

What should I do from the provider console?

systemctl status ssh/sshd, ss -ltnp | grep 22, fix Port/ListenAddress, start the service, then retry from your laptop.

Published · updated .

Try it

Related guides

Newest guides