Locked out of your Linux server? Learn how to instantly diagnose and fix the 'SSH Connection Refused' error on Port 22 using UFW rules, SSH daemon restarts, and remote port scanning tools.
There is nothing more panic-inducing for a system administrator than typing ssh user@server_ip and immediately receiving the fatal ssh: connect to host port 22: Connection refused error.
This error strictly means your server is online, but it is actively rejecting your login attempt. This is almost always caused by a crashed SSH daemon, a misconfigured UFW (Uncomplicated Firewall), or a blocked port at the cloud provider level.
Here is the exact step-by-step command checklist to diagnose the blockage and regain access to your Ubuntu Linux server.
Step 1: Verify Global Port 22 Visibility
Before you start recovering your server via a cloud console, you must determine if the port is completely blocked to the global internet, or if it is just blocking your specific IP address.
- Copy your server's public IP address.
- Navigate to the TraceMyIPOnline Open Port Scanner https://www.tracemyiponline.com/port-checker.
- Enter your server's IP and type 22 in the port field.
- Click Scan.
If the scanner says Closed/Filtered, your server's firewall is physically blocking the port. If the scanner says Open but you still get "Connection Refused" on your terminal, the server has likely banned your specific home IP (often due to Fail2Ban triggering after too many failed password attempts).
[Insert Your Data Here: Share a split-screen screenshot. On the left, show your terminal displaying the "Connection Refused" error. On the right, show the TraceMyIPOnline Open Port Scanner result for Port 22 to demonstrate the diagnostic process.]
Step 2: Access the Server via Cloud Console
Since you cannot use standard SSH, you must log into your hosting provider's dashboard (e.g., AWS EC2, DigitalOcean, Linode) and launch their emergency Web Console or VNC access. This gives you direct terminal access as if you had a monitor plugged into the server.
Step 3: Check and Allow SSH in UFW Firewall
The most common cause of a refused connection on Ubuntu is turning on the UFW firewall without explicitly allowing SSH traffic first.
Once inside your web console, check the firewall status by typing: sudo ufw status
If it says "Status: active" but you do not see 22/tcp or OpenSSH in the allowed list, you have locked yourself out. Fix it instantly with these two commands: sudo ufw allow ssh sudo ufw reload
Run the TraceMyIPOnline Port Scanner again. Port 22 should now be visible.
Step 4: Verify the SSH Daemon is Running
If the firewall is open, the SSH service itself might have crashed due to a bad configuration edit or a memory shortage.
Check the service status: sudo systemctl status ssh
If the text says inactive (dead) or failed, you need to restart the daemon. Run this command: sudo systemctl restart ssh Then enable it to ensure it starts automatically if the server reboots: sudo systemctl enable ssh
Step 5: Check Cloud Provider Security Groups
If your UFW is open and the SSH daemon is running, but you still cannot connect, the block is happening outside your server.
Providers like AWS and Azure use external "Security Groups" that wrap around your server. Log into your cloud dashboard, find the Network/Security tab for your instance, and ensure there is an Inbound Rule allowing TCP traffic on Port 22 from 0.0.0.0/0 (or specifically from your static IP).