Home » How to Fix SSH Connection Refused Error (Quick & Easy)
Systems & Servers

How to Fix SSH Connection Refused Error (Quick & Easy)

✨ Quick Answer

The Connection Refused error when trying to connect via SSH means that the client successfully reached the host server, but the server actively rejected the request on port 22. This usually happens because the OpenSSH service is not active, the port was changed, or a firewall is blocking access.

Quick Diagnostics

Cause
SSH daemon service (sshd) stopped on target server
Solution
Start SSH service daemon: sudo systemctl start sshd
Cause
Security filter or custom port blocked
Solution
Test connection on custom port: ssh -p PORT user@host

The Connection Refused error when trying to connect via SSH means that the client successfully reached the host server, but the server actively rejected the request on port 22. This usually happens because the OpenSSH service is not active, the port was changed, or a firewall is blocking access.

Step-by-Step Solution

  1. 1

    Step 1: Verify the service status on the server

    If you have local access or access through your VPS web console, execute:

    BASH
    sudo systemctl status ssh
    

    If the status is inactive (dead), start and enable the service so it loads with the system immediately:

    BASH
    sudo systemctl enable --now ssh
    
  2. 2

    Step 2: Check the active port

    If the service is running, verify if the default port 22 was changed for security reasons:

    BASH
    sudo grep "Port" /etc/ssh/sshd_config
    

    If the output shows an alternative port (e.g., Port 2222), connect by specifying it in your local terminal using: ssh user@ip -p 2222.

  3. 3

    Step 3: Configure Firewall rules (UFW)

    Ensure the firewall allows incoming connections on the SSH port:

    BASH
    sudo ufw allow ssh
    sudo ufw reload
    

Prevention Advice

Recommended security practices:

  • Do not use the default port 22 on public servers.
  • Disable direct access for the root user by modifying the sshd_config file.
  • Force authentication using SSH Keys instead of conventional passwords.