SSH Connection Refused
SSH Connection Refused
Refused” Error
So if you attempt to use SSH only to see a “Connection refused” error, you may start to feel
concerned. However, this is a common issue, and it’s entirely possible to fix it on your own
with just a bit of troubleshooting. You’ll be back to running commands in no time flat.
In this post, we’ll discuss what SSH is and when to use it. Then we’ll explain some common
reasons your connection may be refused, including in PuTTY. Finally, we’ll provide some
troubleshooting tips.
Unlike File Transfer Protocol (FTP), which only enables you to upload, delete, and edit files
on your server, SSH can accomplish a wide range of tasks. For instance, if an error locks you
out of your WordPress site, you can use SSH to access it remotely.
This protocol also enables you to use several key developer tools, including:
WP-CLI. The WordPress command line. You can use it for a variety of tasks, including
new installations, bulk plugin updates, and media file imports.
Composer. A PHP package manager. It enables you to implement several frameworks
for use in your site’s code by pulling the necessary libraries and dependencies.
Git. A version control system used to track changes in code. This is especially useful for
teams of developers working together on a single project.
npm. A JavaScript package manager. It includes a command-line and JavaScript
software registry. Note: Kinsta customers will need an Enterprise plan in order to access
this feature.
It’s important to note that using SSH is an advanced skill. Generally speaking, lay users of
WordPress should contact their developers or hosting providers for help, rather than trying to
resolve issues with SSH themselves.
Important
A simple mistyped command could ruin your website, so it’s vital that
you know what you’re doing.
Below are some of the most common issues that might be causing problems for you.
In order to connect to your server with SSH, it must be running an SSH daemon – a program
that runs in the background to listen for and accept connections.
If this service is down, you will not be able to successfully connect to your server and may
receive a Connection refused error:
If you suspect that your SSH service might be down, you can run this command to find out:
If the command line returns a status of down, then you’ve likely found the reason behind your
connectivity error.
Info
Although it may seem too simple to be true, it’s possible that you’re just entering the wrong
credentials when trying to connect to your server. There are four pieces of information needed
to run SSH:
Host name. The IP address of the server you’re trying to connect to or your domain
name.
Username. Your (S)FTP username.
Password. Your (S)FTP password.
Port. The default port is 22. However, some hosting providers (including Kinsta) change
their SSH port number for security reasons. If this is the case, you should be able to find
it by logging in to your MyKinsta dashboard.
You can also check to see which port is being used for SSH by running this command:
Check to make sure you’re entering the right credentials and taking into account the
possibility of typos or entering the wrong IP address or port.
A “port” is simply the endpoint to which you’re directed when connecting to your server. 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.
Any open port is a security vulnerability, as hackers can try to exploit it and gain access to the
server. For this reason, unused ports are often closed to prevent attacks.
In the event that port 22, or the custom SSH port for your server, has been closed, you will
likely see a Connection refused error. You can see all the ports listening on your server by
running this command:
As we briefly mentioned earlier, servers use SSH daemons to listen for and accept
connections. Therefore, if the server you’re trying to connect to doesn’t have one installed,
you won’t be able to access it using SSH.
Generally speaking, almost all hosting providers will have SSH daemons installed on their
servers by default. This particular issue is more common on localhost or dedicated servers.
Since open ports present a security risk, firewalls installed to protect servers from hackers
sometimes block connections to them. Unfortunately, this means that even harmless users
who are trying to SSH into their servers may receive a Connection refused error as a result of
firewall settings.
If your setup appears to be in order and you still can’t connect, take a look at your firewall’s
rules. You can display them in your command-line interface with the following commands:
dport 22: This refers to the destination port, which for SSH is usually port 22 (reminder:
Kinsta doesn’t use this port number).
REJECT: This would indicate that connections are being refused from the specified
destination.
DROP: Like REJECT, this means that connections to the relevant port are being
blocked.
If you search the results of the commands above for dport 22, you should be able to
determine if your firewall is preventing an SSH connection. If so, you’ll have to change the
rules to accept requests.
If you’re a PuTTY user and see the Connection refused error, the cause is likely one of those
listed above.
This is an SSH connectivity error like any other, and the troubleshooting tips below should
work whether you’re using PuTTY, Terminal, or any other program for connecting to your
server with SSH.
We’ve taken our knowledge of effective website management at scale, and turned it
into an ebook and video course. Click here to download the The 2020 Guide to
Managing 40+ WordPress Sites!
If you’re attempting to connect to your hosting provider’s server, it may be wiser to contact
support than to try troubleshooting the problem yourself. Users on localhost or dedicated
servers may be able to find further support on more advanced forums if none of the above
solutions works.
Summary
Being able to connect to your server with SSH is convenient in a wide range of situations. It
can enable you to access your site when you’re locked out of your WordPress dashboard, run
commands via WP-CLI, track changes in your site’s code with Git, and more.
Although there are several causes that could be behind your SSH connectivity error, these
are a few of the most common: