Fixes

SSH_Exchange_Identification ‘Connection Closed by Remote Host’? Fix it Here

If you are using the SSH protocol to log in to a remote server, you might sometimes encounter the “SSH_EXCHANGE_IDENTIFICATION ‘CONNECTION CLOSED BY REMOTE HOST” Error while trying to do so. This error mostly occurs due to a server restriction or security protocol that prevents your connection from being made.

ssh_exchange_identification ‘connection closed by remote host’
ssh_exchange_identification ‘connection closed by remote host’

In this article, we have compiled all the steps that you need to take to fix the “ssh_exchange_identification ‘connection closed by remote host ’” error while trying to connect to the remote host. Make sure to follow them word by word as they have been listed below.

Fix the ssh_exchange_identification ‘connection closed by remote host’ Error:

Solution 1: Verify TCP Wrapper Files

There are usually two TCP Wrapper configuration files, the “/ etc / host.allow” and the “/ etc / host.deny” file the files usually contain the network filtering process that allows certain users access while denying others. If the deny configuration file contains the IP address or the range of IP addresses that you are trying to connect from, it usually means that the host is denying connection to your remote host.

Hosts.Deny File
Hosts.Deny File

Otherwise, you can also add the service daemon along with the IP address or the range of IP addresses that your remote host uses to the allowed section to allow the remote host to connect. For that:

Note down the service daemon and the IP address of the remote host that you are trying to connect from. Now, make sure to enter it in the “/ etc / host.allow” file in the same manner as listed below.

ssh: 103.333.21.*

The above line allows all the clients from that IP address range, if you are looking to add only a specific IP address, you can do that by copying the line below and replacing the service daemon and the IP address.

ssh: 103.233.22.1

After adding these files, make sure to save your changes to confirm, alternatively, you can add the following line to allow all remote hosts.

ssh: ALL

Make sure that the “/ etc/ host.deny” file doesn’t contain the line above as that would deny all hosts from connecting. After ensuring this, check to see if the “ssh_exchange_identification: connection closed by remote host aws” error is fixed.

Solution 2: Reconfigure Connection Limits

Sometimes, the server might have a specified number of connections that can be made at a time to conserve the server resources. If this is the case and the limit has been reached, you might be denied the connection.

Therefore, we suggest that you go through the following steps to increase this limit or check if it has been reached. For this, you will need to tamper with the SSH configuration or the SSHD configuration file of the server. For that:

  1. Start the terminal and paste the following command inside of it.
    $  cat / etc / ssh / sshd_config | grep MaxStartups
  2. This will show you the number of connections that can be made at a time, if the limit is lower than you expected, you can increase the limit to allow for more connections to be made.
  3. This should fix the “ssh_exchange_identification ‘connection closed by remote host’” error.

Solution 3: Troubleshoot with SSHD

In some cases, the issue might be caused due to a number of different reasons and you might need to troubleshoot it better. For that, we recommend that you run the sshd without letting it daemonize so that you can get a more accurate description of what exactly might be causing this issue.

In order to do so, we recommend that you follow the procedure below.

  1. Type in the following inside of the terminal and press enter to run it.
    # $(which sshd) -Ddp 10222
  2. After running this, you should get a more accurate description of the error that is causing this issue. Be it an authentication issue or some other misconfiguration.
  3. You cant try to connect to the alternative port using the below command.
    ssh -p 10222 [email protected]
  4. Check if, in this way, you are able to fix the “ssh_exchange_identification: exceeded maxstartups” issue.

Solution 4: Fix Memory Fragmentation Issues

Sometimes, the host’s memory might be fragmented poorly which can prevent it from being able to allocate some memory or a page for the process to host an SSH session. If this is the case, you might get the “ssh_exchange_identification: read: Connection reset by peer” error.

If this has been the reason behind the occurrence of the error, we recommend that you try to connect to the server using different means. Failing that, you can try to restart certain services or the host itself.

Solution 5: Make Sure SSHD is Running

Sometimes, what seems like an obvious thing to do might get overlooked. Therefore, we strongly recommend that you check if the SSHD is running on your server or not. This simple thing can often be overlooked by users which can lead to the “sftp ssh_exchange_identification” error being triggered.

Solution 6: Remake the Deleted Directories

If you have deleted certain directories on your computer, they might not be remade automatically which can lead to the error being triggered. Therefore, we recommend that you go through the following steps to remake the directories that you might have deleted.

In our case, these were the “/ Var / Empty” directory and that can be recreated using the following commands.

drwxr-xr-x. root root / var / empty
drwx--x--x. root root / var / empty/sshd

Solution 7: Install missing Dependencies on Ubuntu/Debian

Sometimes, certain dependencies might be missing on the Ubuntu or the Debian system or they might have been outdated. For that, you can run the following commands to ensure that they are installed. Try any one of the commands and see which one is relevant to your system and verify if the “ssh_exchange_identification esxi” issue is fixed.

$ sudo apt-get upgrade -f
$ sudo yum update

If the issue is still not fixed, contact us for further details.

Back to top button