How to Reset Forgotten Ubuntu User Password: 10 Simple Steps
Forgetting your Ubuntu user password can feel like hitting a wall—especially when the system refuses to let you log in and you have important work waiting inside. Fortunately, Ubuntu provides a safe and effective recovery mechanism that all...

17 min read
Forgetting your Ubuntu user password can feel like hitting a wall—especially when the system refuses to let you log in and you have important work waiting inside. Fortunately, Ubuntu provides a safe and effective recovery mechanism that all...
- What Does “SSH Connection Refused” Actually Mean?
- Common Reasons for SSH Connection Refused on Linux
- Start with the Basics: Is SSH Even There?
If you’ve ever tried connecting to a Linux server using SSH and been hit with the frustrating message:
ssh: connect to host x.x.x.x port 22: Connection refused
You’re not alone.
This error is one of the most common (and confusing) issues Linux users face, whether they’re system administrators, developers, DevOps engineers, or students learning Linux.
The good news?
In most cases, the issue is simple and completely fixable once you understand what’s going wrong.
In this comprehensive guide, you’ll learn how to fix SSH connection refused error on Linux, step by step. We’ll cover every real-world cause, explain why it happens, and show you exact commands to diagnose and fix it—without unnecessary repetition or fluff.
What Does “SSH Connection Refused” Actually Mean?
Before fixing the problem, it’s important to understand what the error means.
When you attempt an SSH connection:
ssh user@server_ip
Your system tries to:
- Reach the remote server over the network
- Connect to a specific port (default: 22)
- Communicate with the SSH service running on that server
A “SSH connection refused” error means:
- The server is reachable, but
- Nothing is listening on the specified port, or
- The connection is being actively blocked or rejected
This is different from errors like:
- No route to host (network issue)
- Connection timed out (firewall or routing problem)
Common Reasons for SSH Connection Refused on Linux
Here are the most common causes you’ll encounter in real environments:
- SSH service is not running
- SSH is installed but disabled
- Incorrect SSH port
- Firewall blocking SSH
- SSH configured to listen on localhost only
- SELinux blocking SSH
- TCP wrappers or access rules blocking connection
- Server-side IP restrictions
- SSH daemon misconfiguration
- Hosting provider or cloud security group issues
We’ll go through each logically and practically.
Start with the Basics: Is SSH Even There?
Picture this: You're SSHing from your laptop, but the remote box doesn't have the server side installed. Rookie mistake, but it happens on fresh minimal installs like Ubuntu Server or CentOS Stream.
First, on your local machine (the client), check if you even have the SSH client: just type ssh. If it spits out usage info, you're good. If "command not found," install it quick:
Ubuntu/Debian:
sudo apt update && sudo apt install openssh-client
Fedora/RHEL/CentOS:
sudo dnf install openssh-clients(oryumon older boxes)
Now, the real issue is usually the server side. SSH into localhost on the target machine (via console, VPS panel, or whatever access you have):
ssh localhost
SSH Connection refused?
Yep, no sshd daemon.
Install it:
Ubuntu/Debian:
sudo apt update && sudo apt install openssh-server
Fedora:
sudo dnf install openssh-server
RHEL/CentOS/AlmaLinux/Rocky:
sudo dnf install openssh-server (RHEL 8+; use yum for 7)
Arch:
sudo pacman -S openssh
Boom, installed. But it won't auto-start on some distros, so enable and fire it up:
sudo systemctl enable --now sshd
(or ssh on Debian/Ubuntu).
Check status:
sudo systemctl status sshd
Should say "active (running)." If not, we dig deeper next.
How to Fix SSH Connection Refused Error on Linux
Step 1: Confirm Basic Network Connectivity
Before touching the server, make sure your system can actually reach it.
Test with ping
ping server_ip
If ping fails:
- The server may be down
- Network routing may be broken
- ICMP may be blocked (not always a problem)
Test the SSH port directly
nc -zv server_ip 22
Or:
telnet server_ip 22
If you see connection refused, the server is reachable—but SSH isn’t accepting connections.
Step 2: Check If SSH Service Is Running on the Server
This is the most common cause of the SSH connection refused error on Linux.
Log into the server locally or via console access.
Check SSH service status
sudo systemctl status ssh
Or on older systems:
sudo systemctl status sshd
If the service is inactive or failed, SSH won’t accept connections.
Start SSH service
sudo systemctl start ssh
Enable it at boot:
sudo systemctl enable ssh
Recheck:
sudo systemctl status ssh
If SSH was stopped, this alone may fix the issue.
Step 3: Install OpenSSH Server (If Missing)
On minimal Linux installations, SSH server may not be installed at all.
Check if SSH server is installed
ssh -V
This checks the client, not the server. To check server:
dpkg -l | grep openssh-server # Ubuntu/Debian
rpm -qa | grep openssh-server # RHEL/CentOS
Install OpenSSH server
Ubuntu / Debian
sudo apt update
sudo apt install openssh-server
RHEL / CentOS / Rocky / Alma
sudo yum install openssh-server
Then start the service:
sudo systemctl start sshd
Step 4: Verify the SSH Port Number
By default, SSH listens on port 22, but many administrators change it for security reasons.
Check SSH listening port
sudo ss -tulpn | grep ssh
Or:
sudo netstat -tulpn | grep ssh
You might see something like:
LISTEN 0 128 0.0.0.0:2222
This means SSH is running on port 2222, not 22.
Connect using the correct port
ssh -p 2222 user@server_ip
If you try port 22 while SSH listens elsewhere, you’ll always get SSH connection refused.
Step 5: Check SSH Configuration File
The SSH daemon configuration file controls how SSH behaves.
Open sshd_config
sudo nano /etc/ssh/sshd_config
Key settings to verify:
Port
Port 22
Ensure it matches the port you’re connecting to.
ListenAddress
ListenAddress 0.0.0.0
If it’s set to:
ListenAddress 127.0.0.1
SSH will only accept local connections, causing remote attempts to be refused.
Protocol
Protocol 2
Restart SSH after changes
sudo systemctl restart ssh
Step 6: Check Firewall Rules (Very Common Cause)
Even if SSH is running, a firewall can block access.
Ubuntu / Debian (UFW)
Check status:
sudo ufw status
Allow SSH:
sudo ufw allow ssh
Or specific port:
sudo ufw allow 22/tcp
Reload firewall:
sudo ufw reload
RHEL / CentOS / Rocky / Alma (Firewalld)
Check firewall:
sudo firewall-cmd --list-all
Allow SSH:
sudo firewall-cmd --permanent --add-service=ssh
Or custom port:
sudo firewall-cmd --permanent --add-port=2222/tcp
Reload:
sudo firewall-cmd --reload
Check iptables (advanced systems)
sudo iptables -L -n
If port 22 is blocked, you’ll need to add a rule to allow it.
Step 7: Check SELinux (RHEL-Based Systems)
SELinux can silently block SSH even when everything else looks correct.
Check SELinux status
sestatus
If SELinux is Enforcing, check SSH ports:
sudo semanage port -l | grep ssh
If your SSH runs on a custom port, allow it:
sudo semanage port -a -t ssh_port_t -p tcp 2222
Restart SSH:
sudo systemctl restart sshd
Step 8: Verify SSH Is Listening on All Interfaces
SSH may be running but bound to the wrong network interface.
Check listening address
ss -tulpn | grep ssh
If you see:
127.0.0.1:22
SSH only listens locally. Fix this in sshd_config:
ListenAddress 0.0.0.0
Restart SSH afterward.
Step 9: Check TCP Wrappers and Access Rules
Some systems restrict SSH using /etc/hosts.allow and /etc/hosts.deny.
Check hosts.deny
cat /etc/hosts.deny
If you see:
sshd: ALL
SSH connections will be refused.
Fix it
Edit /etc/hosts.allow:
sshd: ALL
Or allow specific IPs.
Step 10: Verify Cloud Security Groups (AWS, GCP, Azure)
If you’re using a cloud server, local firewall rules are not enough.
Check:
- AWS Security Groups
- Azure NSG rules
- GCP firewall rules
Ensure:
- SSH port is allowed
- Your IP is permitted
- Correct port is configured
Cloud firewalls often cause SSH connection refused even when Linux is configured correctly.
Step 11: Check SSH Logs for Clues
Logs provide exact reasons for failures.
Ubuntu / Debian
sudo journalctl -u ssh
Or:
sudo tail -f /var/log/auth.log
RHEL / CentOS
sudo tail -f /var/log/secure
Look for:
- Port binding errors
- Permission denied messages
- SELinux denials
- Configuration syntax errors
Step 12: Restart the Server (Last Resort)
If:
- SSH config is correct
- Firewall rules are correct
- SSH service is running
A reboot can resolve stuck services or kernel-level issues:
sudo reboot
You may also like:
Final Thoughts
The SSH connection refused error on Linux looks intimidating at first, but in reality, it’s almost always caused by one of a handful of configuration issues. Once you understand how SSH works behind the scenes, fixing it becomes systematic and predictable.
Whether you’re managing a production server, a cloud VM, or a local Linux machine, the steps in this guide will help you confidently diagnose and resolve the issue without guesswork.
For more help, you can visit official Ubuntu documntation.
Website Vidya Team
Technology educator and researcher at Website Vidya.
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides











Discussion
0No comments on this guide yet. Be the first to share your thoughts or ask a question!