In this article we will explore different ways we can resolve the Connection Refused issue on an Ubuntu/Debian system.
Verify OpenSSH Installation
First, check if OpenSSH is installed on your system or not. The command mentioned below will verify it.
In case OpenSSH is not installed, we will install it by executing the following command:
Check SSH Service
Let’s now check what’s the status of the SSH service on our system. It should be active or in the running state. The reason why you are getting a connection refused error could be the inactive state of SSH on your system. Run the following command to check the status:
The output tells us it is in the active (running state).
If your SSH service is inactive, you can start it by executing the following commands:
Check SSH Server Listening Port
Before trying to connect, first, verify which port is being used by the SSH server to listen to new connections.
Issue the following command to check on which port the OpenSSH server is listening:
As we can see 22 port is in use by OpenSSH to listen to connections.
In case, some other port is being used in place of 22, you will issue the command like this:
Allow SSH in Firewall
To allow the port through firewall, execute this command:
If a port other than 22 is being used, you will issue the command like this:
Once the rules are updated, you will get this output on the terminal:
Reload the firewall with this command to update the rules:
Now check the status of firewall to verify if the SSH port has been allowed or not.
You will see the following message if you are using port 2244 for SSH:
In today’s guide, we discussed several reasons that could be causing the Connection refused error and several ways to resolve this issue.