How to Fix SSH Connection Refused Error (Quick & Easy)
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
sudo systemctl start sshdssh -p PORT user@hostThe 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
Step 1: Verify the service status on the server
If you have local access or access through your VPS web console, execute:
BASHsudo systemctl status sshIf the status is inactive (dead), start and enable the service so it loads with the system immediately:
BASHsudo systemctl enable --now ssh -
2
Step 2: Check the active port
If the service is running, verify if the default port 22 was changed for security reasons:
BASHsudo grep "Port" /etc/ssh/sshd_configIf 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
Step 3: Configure Firewall rules (UFW)
Ensure the firewall allows incoming connections on the SSH port:
BASHsudo 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.