ssh_exchange_identification: connection closed by remote host

If you are trying to SSH into a remote host from a Linux system, the ssh_exchange_identification: connection closed by remote host error is one you might encounter when trying to log in. In this tutorial, we will go over a few different causes for this error and show you how to troubleshoot the connection on your system. Using one of our methods below will hopefully remedy the error and allow you to log in via SSH.

In this tutorial you will learn:

  • How to fix the ssh_exchange_identification: connection closed by remote host SSH error message on Linux
ssh_exchange_identification: connection closed by remote host
ssh_exchange_identification: connection closed by remote host
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software OpenSSH
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Solutions for ssh_exchange_identification: connection closed by remote host




The error occurs when trying to log in to a remote host via SSH on Linux. There are a few different things that could be causing the errror, and it is impossible to know which one is affecting your login until you run through the methods below.

We have listed some of the most common solutions to this problem below. We recommend that you try them one by one until your issue is resolved.

  1. One of the best ways to get started is to try an SSH login from a different host with a separate IP address. Does that host get denied too? This will tell you if the remote server is denying connections to all hosts or just yours.
  2. Check the /etc/hosts.deny file on the server to make sure that your system’s IP address or domain name is not listed in there.
    $ cat /etc/hosts.deny
    
  3. Try deleting the public key of the server from your client system’s known_hosts file. This will force your connection to accept a new key from the server before attempting to log in again.
    $ vim ~/.ssh/known_hosts
    
  4. If there are many users logging in via SSH to the server, check to make sure that the SSH configuration file allows for an appropriate number of simultaneous connections. If you find this number to be too low, consider increasing it.
    $ cat /etc/ssh/sshd_config | grep MaxStartups
    
  5. Check to make sure that there is no rule blocking your connection in the server’s firewall. The syntax for doing this will vary in iptables, ufw, firewalld, etc.
    # iptables -L
    
  6. Check the server for missing dependency packages. Sometimes updating OpenSSL or glibc can break SSH. This is usually resolved by installing missing dependencies. Run the following command to see if your server is missing one.
    $ lsof -n | grep ssh | grep DEL
    
  7. Have you tried rebooting? It is an old adage, but rebooting the system is a common way to fix many issues. This is especially true if memory fragmentation or something similiar is the culprit. Sometimes this may only be a temporary solution.
    $ reboot
    


Closing Thoughts

In this tutorial, we saw several methods that can be used to resolve the ssh_exchange_identification: connection closed by remote host error message on a Linux system. Since there are a variety of potential causes for this error, we have covered numerous methods in this tutorial on how to fix it. Running through these methods should give you an idea of what the cause of the error is on your system, and will hopefully prevent it from happening again.



Comments and Discussions
Linux Forum