If you attempt to use SSH and you see a “connection refused” error, don’t panic because it is a common error and has a fairly simple fix.
Secure shell (SSH) is a WordPress development tool. It grants users access to crucial platforms or software that make coding and other tasks easier, more efficient, and more organized.
What is SSH?
Secure Site Shell(SSH) is a protocol for securing your site’s servers over an unprotected network. In other words, it allows you to safely log in to your remote servers using your preferred command line interface (CLI).
Unlike FTP which allows you to upload, edit and delete files on your servers, SSH offers a wide range of features. For example, if an error code locks you out of your site, you can use SSH to safely log in to it.
It also allows access to several key developer tools such as
- WP CLI
- Composer, a PHP package manager
- Git, a version control system used to track changes in codes.
- Npm, a JavaScript package manager.
It is important to note that using SSH is an advanced skill and so for a WordPress beginner you should contact your hosting providers for assistance.
Why is My SSH Connection Refused?
Certain reasons can cause your SSH connection to be refused. Such reason include
1. Your SSH service is down:
To connect your server with an SSH it must be running an SSH daemon.
This is a program that runs in the background to listen for and accept connections.
If the service is down then it is likely you will see a” connection refused” error. The servers could be down for a variety of reasons. It could be a result of unexpected traffic spikes, resource outages, or even a DDoS attack.
If in case you are unsure if your servers are down you can as well input this command line “Sudo service ssh status”.
2. You may have input the wrong credentials:
There are four pieces of information needed to run SSH which are
- Host name
- A username which could be SFTP or FTP
- A password which could also be SFTP or FTP
- Port in which by default, the port is 22.
However, most hosting providers tend to change their SSH port due to security reasons. A port is simply the endpoint to which you are directed when connecting to your server.
You can also check to see which port is used for the SSH by inputting this command line “grep Port /etc/ssh/sshd_config“
3. You may have the issue of a closed port.
In addition to making sure you have the correct one, you’ll also want to check to see if the port you’re trying to use is open.
So if in the case the port you want to make use of in SSH is closed you are likely to see a “connection refused” error.
If a user wants to know more about the ports listening to his servers he or she can input the shortcodes
"sudo lsof -i -n -P | grep LISTEN"
4. SSH is not installed on the servers
As stated previously, servers make use of SSH daemons to listen and accept connections. So if in this case SSH daemons are not installed on your servers then it is likely you will encounter such errors.
Though by default almost all hosting providers install these daemons on their servers. So in this particular, you are likely to encounter the problem on local hosts or dedicated servers.
5. Firewall settings are preventing an SSH connection.
If your setup appears to be in order but you still can’t connect to SSH, then your firewall settings may be hindrances.
This is because at times firewalls in the course of preventing risks or hackers tend to block connections to servers. You can display these rules by inputting this command
sudo iptables-save # display IPv4
sudo ip6tables-save # display IPv6
The results of this command will vary but there are some key elements you should be on the lookout for. Such elements will help to determine if your firewall is blocking SSH connection
- dport 22: which signifies the destination port which by default is port 22.
- REJECT: This may mean that connections are being refused from a specified destination.
- DROP: Connections to the relevant port are being blocked
If it is that your firewall settings have been blocking the connections then you have to make some adjustments to accept requests.
Why does PuTTY say connection refused?
PuTTY is an SSH client. This platform is the FileZilla equivalent to SSH on Windows machines. So if in this case you are making use of puTTY and you see the error message just know that the reasons may be among those listed above.
How to Troubleshoot SSH Connectivity Error.
When you’re experiencing an SSH connectivity error, there are several troubleshooting steps you can implement
- If in case your SSH service is down: contact your hosting provider to know the exact reason why your SSH server isn’t running. For local hosts or dedicated servers input this command line sudo service ssh restart
- In the case of wrong credentials: After double checking the appropriate port using the command grep Port/etc/ssh/sshd_config try connecting the servers using the correct details.
- If your SSH port is closed, you can either install an SSH daemon on the server you want to connect to or change your firewall settings to accept connections to your SSH port.
- If SSH is not installed on your server you can install one of the SSH tools such as “OpenSSH” on the server that you want to connect to using this command ” sudo apt install openssh-server “
- If your firewall is preventing you from connecting to an SSH server all you have to do is to disable such settings to allow the connection.
Final Thoughts
Connecting to SSH servers comes with a wide range of benefits. As stated before it can allow you to access your site even if you have been locked out from the site.
So if you encounter any connection error message you can immediately control the situation using the simple troubleshooting steps above.
If in the case you want to connect your servers to a hosting provider it is wiser to ask for support rather than attempting to troubleshoot the problem by yourself. Read more WordPress Tutorials.