In this descriptive post, we have listed the causes of “connection refused” error in SSH and their possible fixes.
Possible causes and their solutions for “connection refused” error in Manjaro
There are multiple possibilities that you are getting the connection refused error in Manjaro Linux. In this section we are listing those errors and the relevant solutions as well.
1 – SSH service inactive
There is a possibility that your SSH service is not working properly, and it is causing an interruption in connection. Firstly, look for the status of the SSH service with the help of the command written below.
If the service is down, then it is recommended to restart and enable the SSH service. The commands provided below will assist you to restart, enable and check the status of SSH service:
$ sudo systemctl enable sshd.service
$ sudo systemctl status sshd.service
If the problem still occurs, you may contact your hosting provider to fix the issue.
2 – SSH is not installed
There is a possibility that you do not have the OpenSSH (tool for SSH) installed on your system. To ensure the installation, check the version of OpenSSH with the help of the command written below.
If the above command returns an error (as in our case it returned connection refused), then it means the OpenSSH daemon is missing on your server. To get it, execute the command provided below:
3 – Firewall is blocking the SSH connection
If the SSH service is running properly and still you are not able to connect to the SSH server then the firewall may be blocking your SSH connections. Although disabling the firewall rules may put your system under a security risk, you have to allow SSH through the firewall. You can allow SSH over your firewall with the help of command provided below.
Note : The output below shows that the rules are already added for SSH service.
After doing so, it is recommended to reload the firewall with the help of the command written below.
You can check the status of the firewall and the following command shows the firewall is allowing connections at port 22.
If the SSH server is listening to a port other than 22 then you have to mention that port number. For instance, the command written below will allow SSH server at your selected port number.
4 – SSH is listening to a wrong port
Whenever a connection request is initiated, the default port of SSH(22) is used. One of the reasons for connection refused error is that you may have changed the port but you are trying to connect to the default port. You can check the SSH listening port by accessing the /etc/ssh/sshd_config file. For instance the command provided below will filter(with respect to port) the content of /etc/ssh/sshd_config.
Note : In our case the output shows that the port is 22.
Moreover, if the SSH port is changed from 22 then the connection syntax would be like shown below.
Note : The -p flag is used to make a connection at the desired port. It is observed that if the default port of SSH is changed to another port then you have to specify that port number.
5 – SSH port is closed
Whenever an attempt for a connection is made, SSH sends a request to the specific port. So, to make it successful, the SSH port needs to be opened. As SSH uses port 22, it is mandatory that SSH must allow all incoming connections at port 22. Firslty, check the port 22 is opened or not by using the command stated below.
If the status is listening(as shown in the output) then it’s alright, but if the port is closed then you can use the following ip tables command to open port 22.
There may be a possibility that you are using the wrong credentials and it is suggested to look for the IP address of the server that you want to connect to.
After getting the things on board, you can make an ssh connection as we have made using the command written below.
Note : The username in the above command is “adnan” whereas localhost acts as a hostname.
To make a secure connection using SSH, it is recommended to keep in mind the hurdles in establishing the connection. These hurdles initiate the connection refused error in SSH. This article lists down the reasons for connection refused error and the possible solutions are also listed. Majorly, there are five reasons provided here that may be creating the “connection refused error“. We have provided the possible solutions to all the reasons that are generating the connection refused error.