Skip to content

Q&A · Answered

SSH connection refused - how to troubleshoot

asked 9 months, 1 week ago 2061 views 1 answer
47

I cannot connect to my server via SSH. I get "Connection refused" error. The server is running and I can ping it. What could be wrong?

1 Answer

One accepted
16

Accepted answer

Not confirmed since it was written, 9 months, 1 week ago

The "Connection refused" error typically means SSH service is not running or firewall is blocking. Here's how to fix it:

Step 1: Check if SSH service is running

# Check SSH status
sudo systemctl status sshd
# If not running, start it
sudo systemctl start sshd
sudo systemctl enable sshd

Step 2: Check firewall settings

# For UFW (Ubuntu)
sudo ufw allow ssh
sudo ufw status

# For firewalld (CentOS/RHEL)
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload

Step 3: Verify SSH is listening on correct port

sudo netstat -tlnp | grep ssh
# or
sudo ss -tlnp | grep ssh

Your answer

Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.

Shown beside your answer and never checked, so it cannot be a name someone already has here.

No account needed to answer. Sign in instead and it carries your name and earns reputation.