Linux Commands

Troubleshooting Linux SSH Issues

Network protocol developers, IT gurus, and network administrators use SSH to access computers remotely. It guarantees secure encrypted communications over insecure networks. However, while establishing a connection between two machines usually happen after configuring both server and client sides, this is sometimes not the case.

You will encounter problems when trying to SSH your systems from time to time. Such occurrences are frustrating. As expected, Linux users’ most pertinent question is why they cannot SSH their servers.

This article answers the previous question. Moreover, apart from providing reasons why you may find connection errors when using SSH, this article will also spell out the possible solutions for each reason you may encounter connection failure.

4 Common Reasons Associated With SSH Connection Failure

Troubleshooting SSH is not a complicated process. However, we cannot also term it as an undertaking that is too complicated. All you need is sufficient information to handle each problem when it arises.

The following are some of the causes of common Linux SSH connection errors and possible solutions:

1. When Firewall Restricts SSH Connection

Linux computers come with the UFW firewall in them. You may need to reset your UFW firewall to allow SSH installation and configuration. However, many people opt to enforce strict firewall policies on their networks for security purposes. In such cases, only specific IP addresses can SSH your servers.

A connection failure as a result of firewall configuration will return a message similar to the following:

You can check your system to see if firewall issues are blocking the connection. Also, this problem could be a result of a port problem. Confirm if your system is set to port 22 using the following command:

The previous command should provide you with the port number. Ensure it is port 22. If it is not port 22, please proceed to correct the anomaly. Double-checking the DNS name or IP address if the problem persists will help solve this SSH connection issue.

2. The Public Key Is Not Injected to Your Servers

Initially, everyone used SSH by a password. However, this is no longer the case, particularly with the consensus that SSH by password is extremely dangerous and not secure. Thus, many people now use SSH by key file. This method will occasionally bring up a few issues.

The process of initiating an SSH connection using a key file includes the following:

  • Generate an SSH key. You can proceed to protect your private key using a passphrase, but this is optional.
  • Send the public key to your server manager.
  • The server manager injects the key into the server as part of the authorized keys.

You should be able to SSH once you are through with the process. However, the following problem often occurs:

Notably, the previous error message has two causes. First, it could result from an incorrect pairing of the local public SSH and private keys. The system will undoubtedly reject the use of the private key.

Second, the problem could result from the lack of login privilege for the private key. This condition happens due to incorrect login of the public key or a missing public key. Inform your server manager to perform the necessary changes.

3. SSH Key File Mode Problems

One of the security prerequisites you will find with SSH is its ability to control the opening of your SSH key file. The key file does not get widely open for self-protection. Thus, have a file mode that is either 0400 or 0600. Anything contrary will bring a connection error similar to the following:

You can use the –v flag for verbose output in the following command to correct this anomaly:

4. Host Key Failure

The following image can be confusing and scary in equal measure:

Sometimes, each SSH server has a fingerprint. However, the fingerprint will automatically be different if you use a re-provisioned server or a different one. Your machine will always save the server’s fingerprint on your initial login so that it compares every time you log in. The previous warning comes every time fingerprints do not match.

You could ignore the warning and proceed to SSH if your server was recently re-provisioned. Empty the file or remove the entry from your ~/.ssh/known_hosts directory.


Like every other server management protocol, SSH will often experience problems. The previously mentioned are some of the most common issues you could face. While these issues are incredibly frustrating, there are always solutions to them. Hopefully, the previous illustrations will help you maneuver through them.

About the author

Kennedy Brian

Brian is a computer scientist with a bias for software development, programming, and technical content development. He has been in the profession since 2015. He reads novels, jogs, or plays table tennis whenever not on gadgets. He is an expert in Python, SQL, Java, and data and network security.