Are you facing SSH Connection Refused error?
This guide will help you.
Secure Shell (SSH) is one of the most common tools that a system administrator uses. It's important for managing all of your servers and performing everyday tasks.
SSH Connection Refused happens as a result of different reasons including SSH Service being down, using wrong credentials, firewall settings are preventing the SSH connection, and so on.
This is a connection issue which occurs while trying to connect to your server via SSH, which might result in an error reading "Connection refused".
In this context, we shall look the main causes of SSH connection refused error.
What triggers SSH Connection Refused error?
Different factors causes this to happen.
The main ones are listed below:
i. The SSH service is not working.
ii. Using wrong credentials.
iii. The port that we are trying to use is closed.
iv. SSH is not installed on the server.
v. Firewall settings are preventing an SSH connection.
How to resolve SSH Connection Refused error ?
Apply any of the tips outlined below to fix this SSH error.
1. SSH service is not working
This is the first and foremost thing to check if there is any connection issue in SSH.
Here is the command we run to get it running back:
$ sudo service ssh restart
2. Using wrong credentials
We ensure that we are not using the wrong credentials.
So, we double-check the SSH port using the below command:
$ grep Port /etc/ssh/sshd_config command
We then try connecting again with the correct details.
3. If the SSH port is closed
Sometimes, the routers may block the SSH connections on port 22. So we can use any port forwarding tester to see whether or not the port is visible to the internet.
We can install an SSH daemon on the server we want to connect to. Or we change the firewall rules to accept connections to the SSH port.
4. SSH installation is not proper
It is also necessary to check if the SSH installation is done properly or not.
To check the SSH client installation, we run the below command:
After running the above command, we see the output as below:
ssh connection refused
Also, we can try to initiate a remote connection to localhost and see if the system is accepting connections.
For that, we run the below command:
$ ssh localhost
This must connect to the server.
In case, if the connection refuses then we see the status by running the below command:
$ systemctl status sshd
5. Firewall settings are preventing an SSH connection
We disable the firewall rules blocking the SSH connection by changing the destination port's settings to ACCEPT.