How to Fix Linux SSH Connection Refused Error
In this tutorial, you'll learn about How to Fix Linux SSH Connection Refused Error. We cover key concepts, practical examples, and best practices.
You try to SSH into a server and get Connection refused — the SSH daemon is not running, the port is blocked, or the service is not listening on the expected interface.
The Problem
ssh: connect to host 192.168.1.100 port 22: Connection refused
Step-by-Step Fix
Step 1: Check if SSH daemon is running
sudo systemctl status ssh
Expected if stopped:
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Step 2: Start the SSH service
sudo systemctl start ssh
Enable on boot:
sudo systemctl enable ssh
Step 3: Verify SSH is listening
ss -tlnp | grep :22
Expected:
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1234,fd=3))
If only listening on 127.0.0.1:22, edit /etc/ssh/sshd_config:
# WRONG
ListenAddress 127.0.0.1
# RIGHT
ListenAddress 0.0.0.0
Restart:
sudo systemctl restart ssh
Step 4: Check firewall rules
sudo ufw status
If ufw is active, allow SSH:
sudo ufw allow ssh
Or for iptables:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Step 5: Check if the port is changed
Check /etc/ssh/sshd_config:
grep "^Port " /etc/ssh/sshd_config
If the port is not 22, connect with:
ssh -p 2222 user@host
Step 6: Test from the local machine
ssh localhost
If this works, the issue is the network (firewall, routing).
Detailed Explanation
Detailed Explanation
The Python ecosystem provides powerful libraries for data science, computer vision, and machine learning. However, these libraries have specific API conventions that must be followed for correct results. Common pitfalls include incorrect data types (uint8 vs float), wrong color channel order (BGR vs RGB), missing normalization, and incorrect parameter ordering in function calls. Most computer vision libraries expect images as numpy arrays with specific shapes and data types. OpenCV uses BGR order by default, while matplotlib and most other libraries expect RGB. scikit-image functions often expect float images in the range [0, 1], while OpenCV uses uint8 [0, 255]. These subtle differences are the source of most bugs in image processing pipelines. DodaTech's Durga Antivirus Pro processes millions of images daily for malware detection. Every image goes through a rigorous preprocessing pipeline that normalizes color spaces, data types, and dimensions before any ML model processes it.
Prevention Tips
- Enable SSH on boot with
sudo systemctl enable ssh - Configure firewalls to allow SSH before enabling them
- Use non-standard ports to reduce attack surface
- Test SSH locally before connecting remotely
- Keep SSH and system packages updated
- Debug with console logs at each step to isolate where the issue occurs
- Write unit tests for each component to catch regressions early
- Keep your dependencies updated to benefit from bug fixes
- Monitor application logs in production to detect issues proactively
- Review official documentation when upgrading to a new major version
Common Mistakes with ssh connection
- Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro