SSH Connection Refused: Troubleshooting Guide for Tech Support

Abstract: Resolve SSH connection refused errors by verifying the sshd service status, checking firewall rules, and inspecting daemon configuration.

Created: 2026-08-27 by
A "connection refused" error when using SSH means the remote server is actively rejecting the incoming connection attempt, usually because no service is listening on the expected port or a firewall is blocking it. Since you can ping the server and SSH localhost works, your network connectivity and local SSH client are functional. The issue lies in the remote server's configuration, specifically whether the SSH daemon (sshd) is running, if it is bound to the correct IP address, or if an intermediate firewall like UFW or iptables is dropping the packets before they reach the application.

Verify the SSH Service Status

The most common cause of this error is that the SSH daemon is not running on the target machine. Even if the operating system is up and responding to pings, the specific background process handling SSH connections might be stopped or disabled. You need to access the remote server through an alternative method, such as the cloud provider’s console, physical access, or another management tool, to check the service status. On Linux systems using systemd, which is standard for most modern distributions including Ubuntu and CentOS, you can check the status with the following command:
sudo systemctl status sshd
If the service is inactive or failed, you will see a red indicator or a message stating it is not running. To start the service immediately, use:
sudo systemctl start sshd
To ensure it starts automatically on boot, enable it with:
sudo systemctl enable sshd
If you are using an older system with SysVinit, you would use service sshd status and service sshd start. Note that on some Debian-based systems, the service name might be ssh instead of sshd. Always verify the exact service name by checking the installed packages or looking at the processes list with ps aux | grep ssh.

Check Firewall Rules

If the SSH service is running but you still get a connection refused error, a firewall is likely blocking the connection. Unlike "connection timed out," which suggests a packet was lost or dropped silently, "connection refused" often indicates that the packet reached the host but was rejected by a local firewall rule. Common firewalls include UFW (Uncomplicated Firewall) on Ubuntu, firewalld on CentOS/RHEL, or iptables directly. Check your active rules. For UFW, run:
sudo ufw status
Look for a line allowing traffic on port 22 (the default SSH port). If it is missing or set to deny, add the rule:
sudo ufw allow 22/tcp
For firewalld, you can check zones and services with:
sudo firewall-cmd --list-all
Ensure that the ssh service is listed in the active zone. If not, add it with:
sudo firewall-cmd --permanent --add-service=ssh
Then reload the firewall configuration:
sudo firewall-cmd --reload
Remember that cloud providers like AWS, Azure, and Google Cloud also have their own security groups or network ACLs. These act as an external firewall. If the instance-level firewall allows SSH, but the cloud provider’s security group does not have an inbound rule for TCP port 22, the connection may fail differently depending on the provider. However, if the provider drops the packet silently, you typically get a timeout. A strict "refused" error usually points to the OS-level firewall or the service binding.

Inspect SSH Daemon Configuration

The SSH daemon itself might be configured to listen only on specific interfaces or IP addresses. By default, it listens on all available IPv4 and IPv6 interfaces. However, if the ListenAddress directive in the configuration file is set incorrectly, it will refuse connections from other IPs. Edit the main configuration file, typically located at /etc/ssh/sshd_config, using a text editor like nano or vim:
sudo nano /etc/ssh/sshd_config
Search for the line starting with ListenAddress. If it is commented out (preceded by a #), it defaults to all interfaces. If it is uncommented, ensure it is set to 0.0.0.0 for IPv4 or :: for IPv6, or remove the line entirely to revert to defaults. After making changes, restart the service:
sudo systemctl restart sshd
Additionally, check the Port directive. If the server is configured to listen on a non-standard port, such as 2222, you must specify that port in your SSH client command. Connecting to port 22 when the server is on 2222 will result in a connection refused error because nothing is listening on 22. For more details on fixing similar issues on fresh installs, see our guide on Troubleshooting SSH Connection Issues on a Fresh Install of Ubuntu Server 23.10 on a Raspberry Pi.

Test Connectivity and Diagnostics

Once you have verified the service is running, the firewall is open, and the configuration is correct, test the connection again. Use the verbose flag to get detailed output about where the connection fails:
ssh -v user@remote_server_ip
Look for the line that says "Connection refused." If it appears after attempting to connect to port 22, the issue persists. You can also use telnet or nc (netcat) to test if the port is open without initiating an SSH handshake:
nc -zv remote_server_ip 22
If netcat reports "Connection refused," the problem is definitely at the network or service level. If it reports "Connected," then the issue might be related to SSH protocol versions or key exchange errors, which are different from a simple refusal. In some cases, SELinux (Security-Enhanced Linux) can interfere with SSH. While rare for basic connectivity, mislabeled ports can cause issues. Check SELinux status with getenforce. If it is enforcing, you may need to adjust contexts, though this usually results in permission denied errors rather than connection refused. If you suspect the SSH key authentication is causing early termination, check the server logs. On the remote server, view the auth log:
sudo tail -f /var/log/auth.log
Or on RHEL/CentOS:
sudo tail -f /var/log/secure
This real-time log will show exactly why the connection is being dropped. For related authentication issues, refer to Troubleshooting kex_exchange_identification Error in Linux SSH Connection.

Consider Alternative Access Methods

If you cannot resolve the issue via SSH, consider using alternative management tools provided by your hosting environment. Most cloud providers offer web-based consoles or serial console access. This allows you to interact with the terminal directly through the browser, bypassing network restrictions entirely. From there, you can debug the SSH service, check disk space, review system logs, and restart services without relying on network connectivity. This is particularly useful if the SSH configuration is broken beyond easy repair or if the network interface has been misconfigured.

Frequently Asked Questions

Why does ping work but SSH fails?

Ping uses ICMP protocol, while SSH uses TCP on port 22. Firewalls often allow ICMP for diagnostics but block specific TCP ports for security. Additionally, the SSH service might be down even if the OS is responsive to pings.

How do I know if my firewall is blocking SSH?

Use the nc -zv ip port command. If it returns "Connection refused," the host is reachable but rejecting the port. If it hangs or times out, the packet is being dropped by a firewall or blocked by a security group.

Can a wrong SSH port cause connection refused?

Yes. If the server listens on port 2222 but you try to connect to port 22, the client will receive a refusal because no service is listening on 22. Always verify the port in /etc/ssh/sshd_config.

What should I do if SSH service won't start?

Check the configuration syntax for errors using sshd -t. If there are syntax errors in sshd_config, the service will fail to start. Fix the errors identified by the test command and try restarting again.

Does SELinux cause connection refused errors?

SELinux typically causes "Permission Denied" errors after a connection is established. However, incorrect port labeling can sometimes prevent the service from binding correctly, leading to refusal. Check SELinux logs with ausearch -m avc -ts recent if other fixes fail.

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