SSH Connection Refused – What it is and How to Fix it

ssh connection refused

SSH stands for “Secure Shell” or “Secure Socket Shell”, depending on who you ask. It’s a network protocol that gives you a secure way to access a computer on an unsecured network. This is especially useful if you’re a system admin running your own website. But sometimes, when you’re trying to connect to your server via SSH, you’ll get an error message that says “SSH connection refused”.

Here are five reasons that might happen and five ways to fix it:

5 reasons for “SSH connection refused”:

There are lots of ways to fix “SSH connection refused”, but the right way to fix your error message will depend on what’s causing it. Let’s start with one of the most common reasons you might be seeing the “SSH connection refused” message:

1. Your credentials are wrong.

If you enter the wrong credentials when you’re trying to connect to your server, you’ll get an error message saying “SSH connection refused”.

Here’s all the information you’ll need to enter correctly in order to run SSH:

  • Host name: This is the IP address of your domain name or the server you’re trying to connect to.
  • Username: This is your (S)FTP username.
  • Password: This is your (S)FTP password.
  • Port: The default port is 22, but just in case your hosting providers have changed their SSH port number, check with your host to make sure. You can also find this information by logging in to your dashboard or by running this command:
grep Port /etc/ssh/sshd_config


When you’re sure you have the right credentials, enter the correct information and try connecting again.

2. Your SSH service is down.

An SSH daemon is a program that runs in the background to accept connections. In order to connect to your server using SSH, the daemon must be up and running. If it’s down, you’ll get the “SSH connection refused” error.

The SSH daemon could be down for a number of reasons. For example, DDoS attacks, traffic spikes, and malware attacks can all hobble your server’s SSH daemon. To check whether the daemon is down, run this command:

sudo service ssh status

If it returns a status of “down”, you’ll know that’s what’s causing the error message.


Ask your web hosting provider why your SSH service isn’t running. If you have a dedicated server, you can use this command to restart it:

command sudo service ssh restart

If your SSH service is down more often than not, it might be time to consider switching web hosting providers.

3. Your server doesn’t have SSH.

If the server you’re trying to connect to doesn’t have SSH daemons installed, you’ll get an “SSH connection refused” message if you try to connect to it using SSH. (Most web hosts have SSH daemons installed on their servers by default, but you might run into this problem on dedicated servers.)


Install an SSH tool on the server you’re trying to connect to. Use this command:

sudo apt install openssh-server

4. A port is closed.

A port is the destination you’re trying to connect to. Sometimes, you’ll get an “SSH connection refused” message if you try to connect to the wrong port, but even if the port you’re trying to connect to is correct, you’ll still get this error message if the port is closed.

It’s pretty common to encounter closed ports, since open ports are vulnerable to attacks. To check if the port you’re trying to use is open, run this command:

sudo netstat -plnt

This command will return a list of ports and whether they’re open (“listening”) or closed. Your port should be listed as “LISTEN”. (Remember, this is usually port 22 by default, but some hosting providers change the name of the port.)


Reopen the port to make it connect to the server by installing an SSH daemon on the server you’re trying to connect to or by changing your firewall rules to accept connections to your SSH port.

5. Your firewall is blocking the connection.

Firewalls sometimes block connections to ports to prevent hackers from exploiting them. This can block even well-intentioned users like you from connecting to servers via SSH. So, if everything else appears to be on the up and up, your firewall’s rules might be the problem. Take a look at them to see whether they’re set to block SSH connections. If you see anything like “REJECT” or “DROP” next to the port you’re trying to connect to, this means that your firewall is definitely blocking SSH connections to the port.


Change the port’s settings to ACCEPT.

If you carefully follow the steps in this guide, everything will be running smoothly in no time. Good luck!