List of content you will read in this article:
If you try to utilize SSH and receive a "Connection Refused" message, you can start to worry. But since this is a typical problem, you should be able to resolve it independently with some troubleshooting.
Before we explain the causes of SSH connection refused error and how to fix connection refused error, let's take a quick look at what SSH is.
What is SSH?
A network protocol called Secure Shell (SSH) is used to connect to a web server. In essence, it enables secure encryption for connections to your website, even when using an unprotected network.
SSH and FTP/SFTP, another method for connecting to a website, are frequently contrasted. A TCP/IP network transfers files between computers using FTP (File Transfer Protocol). FTP's lack of encryption is by far its worst drawback. Your connection may be hijacked, and a malicious party may alter your server's files.
SFTP was created as a remedy for this. FTP functions similarly to SFTP, which stands for Secure File Transfer Protocol and SSH File Transfer Protocol. It does this, though, over a secure connection as opposed to an unencrypted one.
SFTP takes advantage of the more advanced SSH protocol to safeguard your connection. SSH allows you to perform many more operations than FTP/SFTP, which can manage files.
- Distant command line. SSH lets you switch from the usual GUI to a Command Line Interface (CLI).
- Login. Unable to log into your WordPress website? SSH is a legitimate method for logging in.
- When you are executing a command remotely. Want to run commands remotely on your server? With SSH, there is no issue.
- Delete any corrupted or compromised files. Using SSH, you can inspect any recently updated files and check whether they contain harmful code if your website has been hacked.
In the end, SSH is a secure protocol for connecting to your server, whereas FTP/SFTP is a method of moving files to and from a server.
What causes connection refused errors?
When attempting to SSH onto your server, there are numerous reasons why you can receive the "Connection refused" issue. It would be best to determine the cause of the system's rejection of your SSH connection before resolving this issue.
Some of the most frequent causes of SSH connection denial are listed below. Then, we’ll discuss how to fix the connection refused error.
How to Fix SSH Connection Refused error? [5 Methods]
1. SSH client not installed
Checking that SSH is properly installed is the first step in troubleshooting any problems.
Your computer needs to have an SSH client program installed to make an SSH connection. It enables SSH command execution and remote server communication. You will receive the SSH "Connection refused" error if the software is not present.
Run the $ ssh command in the Terminal to see if SSH is already installed on your computer.
A list of accessible commands will appear on the Terminal if SSH is installed. If not, the message "command not found" will be displayed. An SSH client does not need to be installed on Macs. Every current macOS version comes with an SSH package that may be used through the Terminal application.
SSH can also be used via Terminal on Linux. However, you must install the SSH client separately because it is not included by default. Depending on your distribution, you may install the OpenSSH package in Linux OS by typing the appropriate lines in Terminal.
Regarding Windows, you must install the SSH client yourself because it doesn't come with one by default. Older versions of Windows do not directly support OpenSSH. As a result, you must set up a client application that enables SSH connections. PuTTY is the one with the most users.
Installed on your local computer, PuTTy establishes a secure connection with the SSH daemon on your web hosting server. All communication between the two parties is secure and encrypted.
Although PuTTY is the most well-known SSH client, there are other choices.
2. A firewall is blocking the SSH port.
Firewall restrictions are among the causes of connection refused errors. Operating systems employ ports to manage data and traffic from many services in an effective manner. Software endpoints called ports are only able to process data from certain services.
For instance, your email client utilizes one port for SMTP email transmissions and another for IMAP or POP3 message reception. Additionally, the SSH service exchanges data using certain ports. Port 22 is the standard. However, a lot of hosting companies utilize their SSH port.
You can execute one of these commands on your server if you are unsure of the port:
$ grep Port /etc/ssh/ssh_config
$ grep Port /etc/ssh/sshd_config
3. The SSH port is closed.
SSH requests a particular port whenever you connect to a distant server. A server has to have the SSH port open to accept this request. The server declines the connection if the port is closed.
Port 22 is what SSH uses by default. If you haven't changed the port's setup, you may see if the server accepts incoming requests. Run the following code to see a list of all ports:
sudo lsof -i -n -P | grep LISTEN
In the output, locate port 22, and verify that the STATE is set to LISTEN. As an alternative, you can determine whether a particular port—in this case, port 22—is open by this code:
sudo lsof -i:22
To fix the connection refused error, you have to enable port 22 to LISTEN to requests using the iptables command:
sudo iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
You can also open ports using the GUI by changing the firewall settings.
4. Wrong SSH credentials or port
One of the common causes of connection refused error is wrong SSH credentials or port. You require multiple credentials to connect from the SSH client to a server. The server will respond with the message "Connection refused" if any of the parameters are incorrect.
The following information is necessary for any SSH connection:
- Hostname: This is the server's address. It might be the server's IP address, name, or domain.
- SSH username: the SSH server username for the website
- Password: It's crucial to understand that the SSH user doesn't have one. The password that is requested is your private SSH key's passphrase. Study up on SSH keys.
- Port: Port 22 is the standard port for SSH connections. However, many hosting companies substitute a unique SSH port for the default one to increase security.
Log into the control panel for your hosting to check sure you have the correct information. The SSH credentials ought to be listed in a separate section.
5. SSH service is down
Given that the issue is coming from your local device or network, most ways to fix the connection refused error stated to this point work. If none were successful, the error could result from a persistent problem with the hosting server.
The SSH service cannot be unavailable if the server is overburdened because of limited resources or significant traffic spikes. For further information and to check the status of the SSH service, get in touch with the support team at your hosting company.
Run this SSH command in the Terminal to turn on the SSH server:
$ sudo service ssh start
Use the command below to restart the SSH server if necessary:
$ sudo service ssh restart
SSH will be well worth your effort because it is a powerful technology. It enables secure site access, file management, process execution, and many other practical functions.
We hope this article helped you fix the SSH connection refused error. Despite the confusion this issue may cause, fixing it shouldn't be too difficult. All you have to do is get familiar with the causes of connection refused errors by running a few of the tests we discussed before.
People also read: