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".
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to fix SSH related errors.
In this context, we shall look the main causes of 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.
Apply any of the tips outlined below to fix this SSH error.
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
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.
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.
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:
$ ssh
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
We disable the firewall rules blocking the SSH connection by changing the destination port's settings to ACCEPT.
This article will guide you on how to resolve SSH connection error occur.
Sometimes while connecting to SSH servers, users often encounter "Connection refused" error by port 22. It happens because of several reasons like SSH service is not running, the port is blocked by the firewall, or the server is using a different port.
It can also occur because of the IP conflict issue.
To SSH on Ubuntu, Open your terminal either by using the Ctrl+Alt+T keyboard shortcut or by clicking on the terminal icon and install the openssh-server package by typing: sudo apt update sudo apt install openssh-server. Once the installation is completed, the SSH service will start automatically.
To resolve ssh connection refused:
1. Install an SSH tool such as OpenSSH on the server you want to connect to using the sudo apt install openssh-server command.
2. If your firewall is blocking your SSH connection. Disable the firewall rules blocking your SSH connection by changing the destination port's settings to ACCEPT.