How to Troubleshoot SSH Connectivity Issues|DigitalOcean Documentation (2024)

SSH is the primary method available for managing DigitalOcean Droplets. Dealing with SSH errors or failures can be frustrating because the errors themselves often prohibit you from accessing your servers.

There are two prerequisites to troubleshooting SSH issues:

  1. Should I troubleshoot SSH? Determine whether troubleshooting is the right decision or if migration/redeployment is more appropriate.
  2. What should I do before troubleshooting SSH?. Make sure the issue is truly with SSH, then review the information and skills necessary to resolve SSH issues, like having root access to the server and understanding how to access and edit files.

When to Consider Migration or Redeployment

To resolve your issue quickly, first determine whether troubleshooting the connection is the right solution for your problem or if you should instead focus on recovering your data for redeployment.

Some issues, such as an accidental recursive rm or chmod command or incorrect network configuration, can lock you out of a Droplet permanently. Other issues may seem like connection problems, but are actually more complex issues with no clear resolution, like corrupted file systems, incorrect file permissions and ownership, and broken system packages and required libraries.

You can typically identify boot errors through the Droplet console startup output. File system issues and startup failures that prevent a working console login session are signs that troubleshooting your network configuration may not be the better option. In situations like this, the best approach is to salvage what you can. In some cases, a good backup or snapshot strategy is the fastest way back to your previous working environment.

What to Do Before Troubleshooting

If you’ve decided that troubleshooting is right for your situation, go through the following steps:

  1. Check the control panel. Before anything else, make sure there are no ongoing issues, like an outage in the region impacting your Droplet.

  2. Check if Droplet is disabled because of abuse. Droplets are sometimes disabled due to the detection of abusive activity. If your Droplet has been disabled, an email has been sent to the email address linked to your DigitalOcean account with the title Networking Disabled: <your-droplet-name>. You can also log in to the support portal to see if any support tickets have been created for your resources.

    If your Droplet has been disabled due to suspected abuse, contact our support team for further information.

  3. Recover root access. If you do not have the current root password, reset it using the reset root password function in the control panel.

  4. Access the Recovery Console. If you cannot log in to the Droplet, the Recovery Console is another way to gain access (as long as your Droplet is running and you have a working root password).

  5. Reboot your Droplet. Many connectivity problems can be resolved after a reboot. If you’re experiencing connectivity issues, try rebooting the Droplet and see if this resolves the issue.

    Before rebooting your Droplet, we highly recommend taking a snapshot of it. This allows you to redeploy your Droplet in its current configuration if rebooting the Droplet causes more serious problems.

    To reboot your Droplet, log in to it and run the following command:

    sudo reboot
  6. Review file management and permissions. Some of these solutions may require you to review or edit files on the system or manage permissions.

  7. Check logs. Once you can get into the Droplet, check the system’s log files for more information to identify the error so you can then look up a solution.

    You can learn more about the logs on your server with this Linux logging tutorial and this journalctl and systemd logging tutorial.

  1. Use verbose SSH output. The level of detail an SSH client provides about the SSH session is generally quiet by default. It’s helpful to have more information when debugging an issue.

    For the OpenSSH client, you can use the -v option with multiple v entries to increase the verbosity of the output, as in ssh -v [emailprotected]. While most issues are revealed with a single v, some issues may benefit from -vvv.

    The PuTTY client supports an Event Log accessible from the context icon in the application window bar. There’s also an option for configuring session logging from the settings page when initiating the connection.

After you decide to troubleshoot an SSH issue instead of migrating or redeploying, you can identify and resolve specific SSH errors based on which phase of a successful SSH connection you need to debug.

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 [emailprotected] may return an error like this:

ssh: Could not resolve hostname example.com: Name or service not known

In PuTTY, you might see an error window with text like this:

Unable to open connection to example.com Host does not exist

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 Droplet IP address as an interim solution, as in ssh [emailprotected] instead of ssh [emailprotected].

The following tutorials are a good resource to begin working out DNS configuration errors:

  • An Introduction to Managing DNS
  • How to Point to DigitalOcean Name Servers From Common Domain Registrars
  • How To Set Up a Host Name with DigitalOcean

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 [emailprotected] may give an error like this:

ssh: connect to host 203.0.113.0 port 22: Connection timed out

In PuTTY, you might see an error window with text like this:

Network error: Connection timed out

Here are some steps you can take to troubleshoot this error.

  • Verify that the host IP address is correct for the Droplet.
  • 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 Droplet.
  • Verify the Droplet 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 [emailprotected] may return an error like this:

ssh: connect to host 203.0.113.0 port 22: Connection refused

In PuTTY, you might see an error window with text like this:

Network error: Connection refused

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 Droplet.
  • 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 Droplet.
  • Verify the Droplet 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 Droplet 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.

  • iptables
  • FirewallD
  • UFW

For Linux systems not running UFW or FirewallD, list your firewall rules using the iptables command with sudo or as the root user.

iptables -nL

The following output would indicate that there are no rules in place that would block SSH traffic:

Chain INPUT (policy ACCEPT)target prot opt source destination Chain FORWARD (policy ACCEPT)target prot opt source destination Chain OUTPUT (policy ACCEPT)target prot opt source destination

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:

firewall-cmd --list-services

The output should reveal the list of services including SSH (default port 22) to indicate that the firewall supports SSH traffic:

dhcpv6-client http ssh

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:

ufw status

The output similarly shows the ports available:

Status: activeTo Action From-- ------ ----22 LIMIT Anywhere 443 ALLOW Anywhere 80 ALLOW Anywhere Anywhere ALLOW 192.168.0.0 22 (v6) LIMIT Anywhere (v6) 443 (v6) ALLOW Anywhere (v6) 80 (v6) ALLOW Anywhere (v6)

Make sure that your SSH port is on the list.

Checking the SSH Service Status

If you can’t SSH to your Droplet, 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 (for example, CentOS and Fedora) call the service sshd while Debian and Ubuntu call it ssh.

  • Using systemctl
  • Using service

Similarly, on a server using systemd (like CentOS 7), use the systemctl command to check the status:

systemctl status sshd

A running service shows output like this, with active (running) on the Active: line.

  sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled) Active: active (running) since Mon 2017-03-20 11:00:22 EDT; 1 months 1 days ago Process: 899 ExecStartPre=/usr/sbin/sshd-keygen (code=exited, status=0/SUCCESS) Main PID: 906 (sshd) CGroup: /system.slice/sshd.service ├ 906 /usr/sbin/sshd -D ├26941 sshd: [accepted] └26942 sshd: [net] 

If the service is not running, the Active line displays inactive followed by recent journal entries for the service:

  sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled) Active: inactive (dead) since Fri 2017-04-21 08:36:13 EDT; 2s ago Process: 906 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=0/SUCCESS) Process: 899 ExecStartPre=/usr/sbin/sshd-keygen (code=exited, status=0/SUCCESS) Main PID: 906 (code=exited, status=0/SUCCESS) 

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):

service ssh status

Output like this, which includes the PID (process ID), indicates that the process is running as expected:

ssh start/running, process 1262

If it isn’t running, you’ll see output indicating the process is stopped:

ssh stop/waiting

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:

grep Port /etc/ssh/sshd_config

You’ll see output like this with the port number:

Port 22

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.

ss -plnt

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.

State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* users:(("sshd",pid=1493,fd=3))LISTEN 0 128 :::22 :::* users:(("sshd",pid=1493,fd=4))

The interface references * and 0.0.0.0 indicate all interfaces on the Droplet. 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 Droplet.

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.

How to Troubleshoot SSH Connectivity Issues|DigitalOcean Documentation (1)

How to Troubleshoot SSH Authentication Issues

Problems with SSH authentication includes permission denied with SSH keys and passwords.

How to Troubleshoot SSH Connectivity Issues|DigitalOcean Documentation (2)

How to Troubleshoot SSH Protocol Issues

Problems during SSH protocol initiation include the client suddenly getting dropped or closed, the client returning errors about cipher negotiation, or issues with an unknown or changed remote host.

How to Troubleshoot SSH Connectivity Issues|DigitalOcean Documentation (3)

How to Troubleshoot SSH Shell Environment Issues

Problems with SSH shell environments include being unable to fork a process, the system reporting it’s not a valid shell, or issues reaching the home directory.

How to Troubleshoot SSH Connectivity Issues|DigitalOcean Documentation (2024)

FAQs

How to Troubleshoot SSH Connectivity Issues|DigitalOcean Documentation? ›

Solution: Restart SSH Service

This action allows the SSH service to restart fresh, potentially resolving any underlying problems and establishing successful SSH connections. Any potential issues or glitches preventing SSH connections can be resolved by restarting the SSH service.

How do I troubleshoot SSH connectivity issues? ›

Troubleshooting the SSH Connection
  1. Verify the connection. Linux or MacOS. ...
  2. Add a public IP address. ...
  3. Instance is on a private subnet. ...
  4. Verify the network security lists. ...
  5. Confirm that the instance is accessible. ...
  6. Connect to the serial console. ...
  7. Confirm that SSH is running on the instance. ...
  8. Capture serial console history.
Jun 13, 2024

How to check SSH connectivity? ›

To Test the SSH Setup on a Host
  1. From another host, use SSH to log in into the host that you are testing as the SSH user. $ ssh -l user-name host-name user-name. The user name for the SSH user's account on the host. ...
  2. In response to the prompt, type your password. If this step succeeds, your setup of SSH is complete.

What is your best option for fixing the SSH problem? ›

Solution: Restart SSH Service

This action allows the SSH service to restart fresh, potentially resolving any underlying problems and establishing successful SSH connections. Any potential issues or glitches preventing SSH connections can be resolved by restarting the SSH service.

How do I fix a SSH error? ›

6 ways to fix the SSH connection refused error
  1. Change the SSH port number. ...
  2. Double-check the credentials. ...
  3. Make sure SSH is enabled. ...
  4. Make sure SSH client is installed. ...
  5. Ensure SSH Daemon is installed on the server. ...
  6. Check your firewall settings.
Jul 23, 2024

Why does my SSH connection suddenly stop working? ›

It can occur due to various reasons: The SSH server may not be running on the remote host. The host or IP address provided could be incorrect. The SSH server may be using a different port than the default port 22.

How do I maintain my SSH connection? ›

Windows operating systems
  1. Start PuTTY.
  2. Load your connection session.
  3. In the Category pane, click Connection.
  4. Under Sending of null packets to keep session active, in the Seconds between keepalives, type 240. ...
  5. In the Category pane, click Session.
  6. Click Save.
  7. Connect to your account and monitor the connection.

How do I check my current SSH connection? ›

To list all connected SSH sessions, you can use the “who -a” command. The -a option shows all users, including those who are not logged in through the system console. The result will show your username, terminal, and login date and time.

How to fix SSH connection timed out? ›

Connection Timeout
  1. Verify that the host IP address is correct for the Droplet.
  2. Verify that your network supports connectivity over the SSH port being used. Some public networks may block port 22 or custom SSH ports. ...
  3. Verify the Droplet firewall rules.
Mar 13, 2024

How to reset SSH connection? ›

Restarting ssh is simple job, exeute:
  1. # /etc/init.d/ssh restart. OR.
  2. # service ssh restart. OR.
  3. $ sudo service ssh restart. If you are using Debian/Ubuntu/Mint Linux with systemd, use the systemctl command:
Mar 5, 2024

How to troubleshoot a connection refused? ›

How to fix the ERR_CONNECTION_REFUSED error
  1. Clear your browser's cache and cookies. ...
  2. Test if the error occurs on different websites. ...
  3. Restart your computer and router. ...
  4. Check your Internet connection. ...
  5. Disable your firewall or antivirus program. ...
  6. Disable the Proxy Server settings or the VPN. ...
  7. Flush the DNS cache.

Why is my SSH connection being refused? ›

Typos or incorrect credentials are common reasons for a refused SSH connection. This includes errors in the specified username or password, or wrong IP address. Any discrepancies lead to authentication failure and result in the connection being refused.

How can I improve my SSH connection? ›

Steps to improve SSH performance:
  1. Disable reverse DNS lookup on the SSH server. ...
  2. Disable GSSAPI authentication on the SSH server. ...
  3. Enable multiplexing to share and reuse SSH connections. ...
  4. Specify the authentication method manually in the SSH client. ...
  5. Use passwordless authentication. ...
  6. Use faster encryption algorithms.

How do I verify SSH service? ›

You can try ssh localhost to test if it is running; if it respons with something like Connection refused , then it is not running. These commands must be run as root. If the server does not start automatically, try using the service sshd start command, or just reboot the computer.

How do I see SSH errors? ›

Launch Control Panel > Administrative Tools > Event Viewer. To see only SSH Server events, select View > Filter to show the filter settings. In the Application Properties > Filter tab, select sshd in the Event source menu to display only SSH Server events. You may also apply other conditions when needed.

Why is my server refusing connection? ›

Well, there could be several possible reasons: The web server hasn't got the proper software installed. The incorrect server has been requested, or a DNS issue. The server software has crashed, or there is server downtime due to maintenance.

Why is my SSH remote connection not working? ›

Verify that the host IP address is correct for the Droplet. 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.

How to check SSH stability? ›

  1. Step 1: Check Network Connectivity. Before diving into SSH configuration, ensure your network connection is stable. ...
  2. Step 2: Verify SSH Server Status. ...
  3. Step 3: Review SSH Configuration. ...
  4. Step 4: Verify Authentication Methods. ...
  5. Step 5: Check Firewall Settings. ...
  6. Step 6: Keep SSH and Related Software Updated.
Oct 31, 2021

Top Articles
Government Bond | Definition, Functions, Pros and Cons
How Much RAM Do Gamers Need? 16GB vs. 32GB vs. 64GB
Joi Databas
Matgyn
Www.1Tamilmv.cafe
How Much Does Dr Pol Charge To Deliver A Calf
Melfme
Kent And Pelczar Obituaries
WK Kellogg Co (KLG) Dividends
Delectable Birthday Dyes
Mawal Gameroom Download
Herbalism Guide Tbc
Slushy Beer Strain
Explore Top Free Tattoo Fonts: Style Your Ink Perfectly! 🖌️
Turning the System On or Off
Valentina Gonzalez Leak
Costco Gas Foster City
Echo & the Bunnymen - Lips Like Sugar Lyrics
Craigslist Pets Athens Ohio
Seattle Rpz
charleston cars & trucks - by owner - craigslist
Sport-News heute – Schweiz & International | aktuell im Ticker
My Homework Lesson 11 Volume Of Composite Figures Answer Key
Water Trends Inferno Pool Cleaner
Schedule An Oil Change At Walmart
Persona 5 Royal Fusion Calculator (Fusion list with guide)
Phoebus uses last-second touchdown to stun Salem for Class 4 football title
Puretalkusa.com/Amac
At&T Outage Today 2022 Map
Jayah And Kimora Phone Number
Integer Division Matlab
Https E22 Ultipro Com Login Aspx
HP PARTSURFER - spare part search portal
Mississippi Craigslist
The Procurement Acronyms And Abbreviations That You Need To Know Short Forms Used In Procurement
Ipcam Telegram Group
Motor Mounts
T&J Agnes Theaters
Bella Thorne Bikini Uncensored
Gifford Christmas Craft Show 2022
2700 Yen To Usd
F9 2385
Xxn Abbreviation List 2023
Stranahan Theater Dress Code
Costco Gas Foster City
Sandra Sancc
York Racecourse | Racecourses.net
Germany’s intensely private and immensely wealthy Reimann family
What Does the Death Card Mean in Tarot?
The Hardest Quests in Old School RuneScape (Ranked) – FandomSpot
Prologistix Ein Number
라이키 유출
Latest Posts
Article information

Author: Jamar Nader

Last Updated:

Views: 5810

Rating: 4.4 / 5 (55 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Jamar Nader

Birthday: 1995-02-28

Address: Apt. 536 6162 Reichel Greens, Port Zackaryside, CT 22682-9804

Phone: +9958384818317

Job: IT Representative

Hobby: Scrapbooking, Hiking, Hunting, Kite flying, Blacksmithing, Video gaming, Foraging

Introduction: My name is Jamar Nader, I am a fine, shiny, colorful, bright, nice, perfect, curious person who loves writing and wants to share my knowledge and understanding with you.