How to fix ‘SSH connection refused’

The SSH connection refused error message can have different causes. There are some obvious solutions to this problem. Let’s find out why you are getting this message on your terminal.

The problem of not establishing a connection is a problem a lot of people have. It is very frustrating if you don’t know how to fix it. In this article, we are going to resolve your issues for a refused connection. We have split the article into 2 parts so you can find your solution faster.

SSH connection refused on Ubuntu

There is a quick fix available for those who use Ubuntu Live Server. If you have tried using SSH and you got the error “SSH connection refused”, then you should try out the following.

Start by installing tasksel with apt-get by typing

$ sudo apt-get install tasksel

Go ahead and start it up by typing:

$ sudo tasksel

Now you will see the following screen with several options. Choose the option “OpenSSH Server“. Press “Enter“.

It will install SSH and run it as a service.

After that, try to open an SSH connection. Enter your username and password and you should be in.

SSH connection refused on Windows by using PuTTy

Yes, using PuTTy is a friendly experience until you start encountering errors. With the solutions below you can solve the connection error you are facing.

We list every possible solution below. They are for Windows users who get a connection refused error when using PuTTy. If one method does not solve your problem, try the next one.

Solution 1: reach out to the network administrator

Sometimes, the solution is as simple as reaching out to the system administrator. In fact, it should be your first type of action.

The system administrator can give you the correct permissions to connect. It is possible that by default unknown users are not allowed to establish a connection. If you are not sure you have the correct permissions, this is the first step you have to try.

If this is the case, the network administrator can give you access and the right permissions. With these permissions, you can connect to the machine.

Solution 2: enable SSH

This is a common cause of the error. It could be that SSH is not enabled in the settings of your computer. So it is as simple as checking the settings of your device and changing the SSH status from disable to enable.

If you are using a Raspberry Pi, you have to check the following. Configuration > Interfaces > SSH > Enable. When you have checked this setting you should be able to get an established connection.

Solution 3: verify the nameservers that point to your machine

You need to be sure that the DNS settings are correct. Use the correct nameservers that have records that point to your machine. This is especially a likely case if your server and your domain are new.

How it works is that your domain registrar lets you point your domain to a hosting service via the nameservers. You have to change the nameserver settings if you use other nameservers. If you don’t use the correct nameservers, a connection refused error may occur.

To solve this problem you can log in to the site where you registered your domain name. Verify that the nameservers are correct and pointing to your hosting provider.

Solution 4: check the blacklisted and whitelisted IP addresses on the server

If your server is set up the right way, it should only allow connections from IP addresses it knows. You can whitelist IP addresses in the config file of your server.

Changed to a new network, IP address or internet provider? Add your new IP address to the whitelisted IP addresses on your machine. Contact your network administrator if you can’t add the IP address yourself.

A blacklisted IP address might also be the case. Then you need to make sure your IP address is getting removed from the blacklist and. Even try to add it to the whitelist if that is possible. Ask your network admin for support.

Solution 5: try disabling your firewall

An antivirus program or firewall might be blocking your connection. They are doing their job. There is an easy way to check if this is the case. Disable your antivirus and firewall programs and see if the connection gets accepted. If this is the case, those programs are blocking your connection. Now you know you have to adjust your settings in the firewall or antivirus to allow connections. For instructions on how to do this, you can follow the manual of your software.

To disable the Windows firewall, go to:

Start > Settings > Update and Security > Windows Security > Firewall & Network protection

Then choose your preferred network type and disable Windows Defender Firewall.

When you disable the firewall you are no longer protected against possible threats.

Solution 6: reboot server

If none of the solutions above worked, you can try to reboot the server or restart the SSH server.

To reboot the server you can use the command

sudo reboot

If you want to restart the SSH server, use the following command

service sshd restart

If you did not set up this server where you get the error message, try to reach out to the person who did. They are able to help you with the configuration and getting the right permissions.

Final remarks

Whether it is Ubuntu Live Server or PuTTy, the “connection refused error” can be a daunting problem. But it should not cause too much worry. Try out the solutions provided above. You can ask your question in a related forum if it isn’t solved. But make sure you have tried all the solutions above.

If you have another fix for this problem that we didn’t cover, please reach out to us. We will add your solution for others to benefit.