An SSH client needs a TCP connection before the server can check a password or key. On Ubuntu with socket-activated OpenSSH, fixing a refused SSH connection starts with finding the destination the client tried and checking whether OpenSSH is listening there.

A closed port and a firewall that actively rejects connections can produce the same error. On hosts using socket activation, systemd can listen on behalf of OpenSSH and start it on demand. An inactive ssh.service is normal while ssh.socket is listening.

Server-side checks require console access or an existing administrative session with sudo privileges. The local TCP check uses OpenBSD Netcat on the server.

Steps to fix SSH connection refused:

  1. Reproduce the refusal with the original SSH client and connection options.
    $ ssh -v -S none -p 22 user@host.example.net
    ##### snipped #####
    debug1: Connecting to host.example.net [192.0.2.40] port 22.
    debug1: connect to address 192.0.2.40 port 22: Connection refused
    ssh: connect to host host.example.net port 22: Connection refused

    The command uses the account, destination, port, and options from your failed login. -v shows the IP and port on the Connecting to line. -S none forces a fresh connection. If the port is wrong, use the server's assigned port. If a jump host is being refused, diagnose that hop first.

  2. Confirm the refused IP address on the intended server.
    $ ip -brief address
    ##### snipped #####
    eth0@if1881      UP             192.0.2.40/24

    The server in the example lists 192.0.2.40. If a direct connection used the wrong address, check the hostname or client alias. If port forwarding changes the address or port, stop here and check the mapping to the server.

  3. Check the server for a TCP listener on the refused port.
    $ sudo ss -ltnp 'sport = :22'
    State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess

    The filter takes the port shown by the client. A header alone means no process is listening on that port. If the owner is systemd with pid=1, use the unit check to identify the socket. If sshd listens on the target address or a wildcard that covers it, skip to the local TCP check. If SSH listens only on another address or a different service owns the port, stop here.

  4. Check the state of the OpenSSH socket and service on the server.
    $ systemctl status ssh.socket ssh.service --no-pager
    ○ ssh.socket - OpenBSD Secure Shell server socket
         Loaded: loaded (/usr/lib/systemd/system/ssh.socket; enabled; preset: enabled)
         Active: inactive (dead) since Sat 2026-11-21 10:37:22 UTC; 330ms ago
    ##### snipped #####
         Listen: 0.0.0.0:22 (Stream)
                 [::]:22 (Stream)
    ##### snipped #####
    ○ ssh.service - OpenBSD Secure Shell server
         Loaded: loaded (/usr/lib/systemd/system/ssh.service; disabled; preset: enabled)
         Active: inactive (dead) since Sat 2026-11-21 10:37:22 UTC; 332ms ago
    ##### snipped #####

    The start step applies when the port has no listener, ssh.socket is enabled and inactive (dead) with the intended Listen addresses and port, and ssh.service is disabled and inactive. If PID 1 owns the port and ssh.socket is active (listening) with matching Listen entries, skip the start and run the local TCP check.

    For unclear unit states or a daemon-managed ssh.service, as on a default Debian setup or an Ubuntu host switched to daemon mode, see the OpenSSH service guide.

    Starting the socket makes its configured port reachable wherever network policy permits. Proceed only if SSH should accept connections now and your console or existing session can stay open until a new login succeeds.

  5. Start the stopped SSH socket on the server.
    $ sudo systemctl start ssh.socket
  6. Test the SSH port from the server using its own address.
    $ nc -vz -w 5 192.0.2.40 22
    Connection to 192.0.2.40 22 port [tcp/*] succeeded!

    The probe uses the server IP and port from the earlier checks. succeeded confirms a local TCP connection. If the probe fails, stop here and check the listener on that address and port.

  7. Log in again from the original client using the same SSH command.
    $ ssh -v -S none -p 22 user@host.example.net
    ##### snipped #####
    Authenticated to host.example.net ([192.0.2.40]:22) using "publickey".
    ##### snipped #####
    user@host:~$

    A remote shell prompt confirms the login. An unverified host key can lead you to an impersonating server. If prompted, accept the key only if its fingerprint matches one from a trusted source.

    If the local probe succeeded but the client still gets a refusal, sudo nft list ruleset shows the active policy on an nftables-managed server. A reject rule covering the client's source address and SSH port can explain the refusal. If you manage the firewall and the client should have access, correct the matching rule and retry from the same client. If there is no match on the server, check the upstream firewall policy.

Share this guide