SSH Connection Refused - Troubleshooting Guide

Abstract: Resolve SSH connection refused errors by verifying the sshd service status, checking firewall rules for port 22 access, and ensuring the daemon is bound to the correct network interface.

Created: 2026-08-09 by

When SSH reports "Connection Refused" despite a successful ping, the remote server is actively rejecting the TCP handshake because no service is listening on port 22 or a firewall is dropping the packets. This guide details how to verify the SSH daemon status, check local and remote firewalls, and inspect network routing to restore connectivity.

Verify the SSH Daemon Status

The most common cause for this error is that the sshd service is not running on the target machine. Even if the server responds to ICMP echo requests (ping), it will reject any attempt to establish an SSH connection if the background process is stopped or crashed. You must have console access to the remote server, such as via a cloud provider’s web console or physical keyboard, to diagnose this. First, check if the service is active using the system initialization tool. On modern Linux distributions using systemd, run:
systemctl status sshd
If the output indicates the service is inactive or failed, start it immediately with:
sudo systemctl start sshd
To ensure it starts automatically after a reboot, enable the service:
sudo systemctl enable sshd
On older systems using SysVinit, you might need to use service ssh start. If the service is running but still refuses connections, check the logs for errors during startup by viewing /var/log/auth.log or /var/log/secure. Misconfigured host keys or invalid configuration files in /etc/ssh/sshd_config can prevent the daemon from binding to the socket.

Check Firewall Rules

If the daemon is running, the next likely culprit is a firewall blocking incoming traffic on port 22. Firewalls operate at the network layer and can drop packets before they reach the application layer, resulting in a timeout rather than a refusal, but some configurations explicitly send a TCP RST packet, which triggers the "Connection Refused" message locally. On the remote server, inspect the active firewall rules. For ufw (Uncomplicated Firewall) commonly used on Ubuntu, check the status with:
sudo ufw status
Ensure there is a rule allowing traffic from your IP address or all sources to port 22. If the status shows inactive, the firewall is not the issue. However, if it is active, allow SSH with:
sudo ufw allow ssh
For iptables users, list the rules to see if port 22 is accepted:
sudo iptables -L -n -v
Look for a chain named INPUT that accepts TCP traffic on dport 22. If you are managing a cloud instance, remember that cloud providers also have security groups or network ACLs configured at the hypervisor level. These act as an external firewall. Log into your cloud provider’s dashboard and verify that inbound rules permit TCP traffic on port 22 from your current public IP address.

Inspect Network Configuration and Binding

Sometimes the SSH daemon is running and the firewall is open, but the service is bound to a specific network interface that does not include your source IP. By default, sshd listens on all interfaces (0.0.0.0). However, administrators may restrict it to localhost (127.0.0.1) for security reasons. Check the ListenAddress directive in /etc/ssh/sshd_config. If it is set to 127.0.0.1, remote connections will be refused. Change this to 0.0.0.0 or comment out the line to listen on all interfaces, then restart the service. Additionally, verify the port number. While 22 is standard, some servers change the port to avoid automated bots. If you recently changed the port, you must specify it in your client command:
ssh -p 2222 user@remote_host
If you are connecting through a proxy or NAT device, ensure that port forwarding is correctly configured. A mismatched port mapping between the router and the internal server IP will result in connection failures.

Diagnostic Steps When Local Login Works

The original problem statement mentions being able to login locally. This confirms the OS is functional and the user account exists. It isolates the issue to network accessibility. Use telnet or nc (netcat) from the client machine to test the raw TCP connection to the remote port.
nc -zv remote_host 22
If this fails with "Connection refused," the issue is definitely on the server side (daemon down, firewall, or binding). If it hangs or times out, the packet is being dropped by a firewall or routed incorrectly. If it succeeds, but SSH still fails, check for DNS resolution issues or incorrect hostname entries in /etc/hosts. For more complex scenarios involving virtualization or multi-hop setups, refer to our guide on WSL2: SSH Server on Ubuntu not Working, which addresses similar binding issues in containerized environments. Another relevant resource is Troubleshooting SSH WSL Machine: Can't Connect to Localhost, which helps if your local environment is misconfiguring the loopback adapter.

Frequently Asked Questions

Why can I ping the server but SSH is refused?

Ping uses ICMP protocol, while SSH uses TCP. A server can be configured to respond to pings while blocking or not running the SSH service on port 22. This discrepancy indicates the network path is open, but the specific application service is unavailable or restricted.

How do I check if port 22 is open from my client?

Use the netcat command nc -zv ip_address 22 or telnet telnet ip_address 22. If these tools report a successful connection, the network path is clear, and the issue lies within the SSH configuration or authentication methods on the server.

What if I changed the SSH port but forgot to update my client?

You must explicitly specify the new port using the -p flag followed by the port number in your SSH command. Without this flag, the client defaults to port 22 and will receive a connection refused error if the server is only listening on a different port.

Can a VPN cause SSH connection refused errors?

Yes, if your VPN routes traffic differently or blocks certain ports, it may interfere with the connection. Additionally, if the VPN splits tunneling incorrectly, your client might try to connect to a local gateway instead of the remote server, leading to refusal if no SSH service runs on the gateway.

Is it safe to disable the firewall entirely to fix this?

No, disabling the firewall entirely exposes your server to all incoming traffic, including brute-force attacks. Instead, create specific rules to allow only necessary ports like 22 from trusted IP ranges. Always keep the firewall enabled and manage access through precise allow-lists.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More