TR EN

How to Fix SSH Connection Refused (Port 22) on Ubuntu/Linux

Connection refused can mean no listener, a different destination or active rejection. Check the actual client path, listener and access rules before making changes.

First identify the failure

Connection refused means the TCP attempt was actively rejected; no listener, a different port or an active rejection are possible. A timeout suggests the connection did not complete in time and can involve filtering or routing. Permission denied occurs later during authentication and needs a different investigation. The message alone does not prove the cause.

1. Confirm where the client is connecting

On the machine running your SSH client, inspect the effective destination and port for your own SSH alias:

ssh -G YOUR_ALIAS | grep -E '^(hostname|port|user|proxyjump) '

Replace YOUR_ALIAS with your configured alias. A proxy or jump host changes the path; if a port differs from 22, use that configured port in your checks. Output can contain server names and usernames: redact it before sharing. See the OpenSSH client manual.

2. Check the listener from the server console

Use an existing session or your hosting provider’s recovery console. On Linux:

sudo systemctl status ssh
sudo systemctl status sshd
sudo ss -ltnp

The service may be named ssh or sshd; one command may report that the unit does not exist. Compare the listener address and configured port. A service listening only on loopback is not reachable directly from another machine. Socket activation can also affect how a service listens; check your distribution's configuration before changing it.

3. Check effective SSH and firewall settings

sudo sshd -t
sudo sshd -T | grep -E '^(port|listenaddress) '
sudo ufw status numbered

sshd -t validates configuration and keys; sshd -T shows effective configuration. It may not reflect service-manager command-line options or socket activation. UFW is only one possible firewall; an inactive UFW does not prove another layer is open. Review relevant host and provider network rules for the actual source, destination, port and IP version. See OpenSSH server options and Ubuntu firewall documentation.

4. Verify from the affected network

Retry from the client’s network using its actual configured host and port. An external checker sees the checker’s network path, which may differ from a VPN, bastion or office network. For a public target you own, the port 22 tool checks only reachability from our server; it does not verify SSH login or your firewall policy.

Before changing anything: keep a working session and recovery console available. Do not open SSH to the whole internet or restart a service as a first step. If a rule or service change is needed, use your organization’s approved access policy and validate a separate connection before closing the old one.

Reviewed 14 November 2026. Related: SSH port 22 and 502 upstream diagnostics.

Frequently Asked Questions

Difference between Connection Timed Out vs Connection Refused?
A timeout means the connection was not established within the allowed time; filtering, routing or server problems are possible. Refusal can occur when no service is listening or a system actively rejects the connection. The error text alone does not establish the cause.
Is changing the default SSH port effective?
Changing the port alone does not establish security or prevent discovery. Keep authentication and network access controls in place. Verify the new port with a separate connection and a recovery path before closing the working session.