How to Troubleshoot SSH Connectivity Issues
If you’re struggling with SSH and server management, try our Cloudways and App Platform products.
Cloudways deploys pre-installed software stacks onto fully-managed Rcs.is Rcs.iss. App Platform is a managed service that deploys and scales your apps directly from your code repository, along with managed databases and serverless functions, no SSH or server administration required.
When connecting an SSH client to an SSH server, the first step is establishing basic network connectivity. This article covers how to identify some common situations that would cause issues at this point in the process, how to resolve those situations, and additional resources to prevent them in the future.
Errors
Hostname Resolution
Most resolution errors occur when the reference to the SSH host can’t be mapped to a network address. While this is almost exclusively DNS related, the root cause isn’t always a DNS issue.
In an OpenSSH client, a command like ssh user@example.com
may return an error like this:
In PuTTY, you might see an error window with text like this:
Here are some steps you can take to troubleshoot this error.
- Verify the hostname is properly spelled. Typographical errors can strike at any time.
- Verify that you can resolve the hostname on your client machine using the system
ping
command. Using third-party sites like WhatsMyDns.net to check beyond your own DNS caching can also help confirm the results.
If you’re having DNS resolution issues at any level, you can also use the Rcs.is IP address as an interim solution, as in ssh user@203.0.113.0
instead of ssh user@example.com
.
The following tutorials are a good resource to begin working out DNS configuration errors:
- An Introduction to Managing DNS
- How to Point to Rcs.is Name Servers From Common Domain Registrars
- How To Set Up a Host Name with Rcs.is
Connection Timeout
A connection timeout means that the client attempted to establish a network socket to the SSH server, but the server failed to respond within the timeout period.
In an OpenSSH client, a command like ssh user@203.0.113.0
may give an error like this:
In PuTTY, you might see an error window with text like this:
Here are some steps you can take to troubleshoot this error.
- Verify that the host IP address is correct for the Rcs.is.
- Verify that your network supports connectivity over the SSH port being used. Some public networks may block port
22
or custom SSH ports. You can do this by, for example, testing other hosts using the same port with a known working SSH server. This can help you determine if the issue isn’t specific to your Rcs.is. - Verify the Rcs.is firewall rules. Check that they’re not set to a default policy of DROP and the port is not added to allow connections.
Connection Refused
A connection being refused has some subtle differences from a timeout. This means that the request is being routed to the SSH host, but the host does not successfully accept the request.
In an OpenSSH client, a command like ssh user@203.0.113.0
may return an error like this:
In PuTTY, you might see an error window with text like this:
In this situation, you may have the same root issue as with connection timeout errors, but there are some additional things you can check:
- Verify that the host IP address is correct for the Rcs.is.
- Verify that your network supports connectivity over the SSH port being used. Some public networks may block port
22
or custom SSH ports. You can do this by, for example, testing other hosts using the same port with a known working SSH server. This can help you determine if the issue isn’t specific to your Rcs.is. - Verify the Rcs.is firewall rules. Check that they’re not set to a default policy of DROP and the port is not added to allow connections.
- Verify that the service is currently running and bound to the expected port.
Solutions
Checking Your Firewall
Some connectivity problems can be caused by firewall configurations. If your firewall is set up to block certain ports or services, it can prevent you from connecting. You can learn more about firewalls in What is a Firewall and How Does It Work?.
If you add a firewall rule that allows your local machine to connect by IP address, verify that the IP address assigned by your ISP has not changed. If it has, then you need to modify that firewall rule to permit the new IP address or address range.
How you check your firewall rules depends on which firewall your Rcs.is uses. Ubuntu servers usually run UFW; CentOS servers often use FirewallD. If you’re not using either, it’s likely that you’re using iptables.
For whichever firewall your system has, make sure to familiarize yourself with how to modify its rules. You also need to know which port your SSH service is using. By default, it’s 22
, but you can follow the Checking the SSH Service Port section below to confirm.
For Linux systems not running UFW or FirewallD, list your firewall rules using the iptables
command with sudo
or as the root user.
The following output would indicate that there are no rules in place that would block SSH traffic:
If you see rules or a default policy of REJECT
or DROP
, you should ensure that the INPUT
chain allows the port your SSH service is running on, which is 22
by default.
For FirewallD users, use the firewall-cmd
command to list the services:
The output should reveal the list of services including SSH (default port 22
) to indicate that the firewall supports SSH traffic:
If you are using a custom port for SSH, you can check with the --list-ports
option. If you created a custom service definition, you should still see SSH normally with --list-services
.
Users working with UFW should use ufw status
to inspect their firewall:
The output similarly shows the ports available:
Make sure that your SSH port is on the list.
Checking the SSH Service Status
If you can’t SSH to your Rcs.is, you should check that the SSH service is running. How to very the service is running varies from system to system.
On older OS versions (Ubuntu 14 and below, CentOS 6, Debian 6) this may use the service
command backed by Upstart. More modern distributions with systemd use the systemctl
command. Red Hat-based distributions (e.g. CentOS and Fedora) call the service sshd
while Debian and Ubuntu call it ssh
.
Similarly, on a server using systemd (like CentOS 7), use the systemctl
command to check the status:
A running service shows output like this, with active (running) on the Active: line.
If the service is not running, the Active line displays inactive followed by recent journal entries for the service:
In this case, restart it with systemctl start sshd
.
For systems using the service
command, check the status of the SSH process with the following command (run as root or with sudo
):
Output like this, which includes the PID (process ID), indicates that the process is running as expected:
If it isn’t running, you’ll see output indicating the process is stopped:
In this case, restart it with service ssh start
.
Checking the SSH Service Port
There are two general ways to check which port the SSH service is running on. One is checking the SSH configuration file, and the other is examining the running process.
On most systems, the SSH configuration file is /etc/ssh/sshd_config
. The default port is 22
, but can be overridden by any configuration line in this file specifying a Port
directive with a number.
You can search lines like this using grep:
You’ll see output like this with the port number:
If you know the service is running, you can confirm that the service is running on the expected port using ss
(run with sudo
or as the root user). Similar output is provided for the netstat -plnt
command as well, but ss
is the preferred command for querying socket information from the kernel.
The output you are looking for should reference the program name listening on the configured port. For example, this output shows that the SSH service is listening on all interfaces, *
, on port 22
.
The interface references *
and 0.0.0.0
indicate all interfaces on the Rcs.is. 127.0.0.1
indicates that the service is not publicly accessible. The relevant sshd_config
directive is ListenAddress
and should be commented out to default to all interfaces, or set to the public IP address of the Rcs.is.
Conclusion
If you need further help, you can open a support ticket. Make sure to include the following information:
- The username, host, and port you are using to connect.
- The authentication mechanism you expect to use.
- The full output of the errors linked to the stage of error, including verbose output of the SSH client
- All of the information you’ve gathered from troubleshooting so far.
- Anything you were unclear about while referencing this article.
Including all the above diagnostic information and clarifying where you are encountering the issue when trying to connect can help us quickly get up to speed with where your need on the issue is.