SSH Connection: ssh_exchange_identifcation

Solution 1:

This is how I solved the "ssh_exchange_identification: Connection closed by remote host" error when connecting to an SSH server.

I got this error when trying to connect to an embedded Linux machine, after unpacking a package to root. Lots of library files were replaced, including libssl.

Trying to connect:

chetic@ubuntu:~$ ssh -v [email protected]
OpenSSH_6.2p2 Ubuntu-6ubuntu0.3, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to SC [192.168.1.100] port 22.
debug1: Connection established.
debug1: identity file /home/delaval/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/delaval/.ssh/id_rsa-cert type -1
debug1: identity file /home/delaval/.ssh/id_dsa type -1
debug1: identity file /home/delaval/.ssh/id_dsa-cert type -1
debug1: identity file /home/delaval/.ssh/id_ecdsa type -1
debug1: identity file /home/delaval/.ssh/id_ecdsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2p2 Ubuntu-6ubuntu0.3
ssh_exchange_identification: read: Connection reset by peer

Googling only seemed to suggest checking hosts.deny and hosts.allow, but my target machine had no such files.

After a reboot (as per Karthik's suggestion) sshd was not running. I tried manually starting sshd on target:

# sshd
OpenSSL version mismatch. Built against 1000002f, you have 1000105f

I replaced /usr/lib/libssl.a with the original version and started sshd and things were back to normal. The problem was in my case caused by an incorrect version in the package I originally unpacked to root.

Solution 2:

I was getting the same error (but from any machine, including the troublesome machine via ssh localhost).

It started when I migrated a users profile; i.e. after copying files as root, then did commands like chown -R username /Users/username/Destop

anyway, totally unsure why /var/empty owner was changed to username, but ssh definitely needs /var/empty to be owned by root (otherwise you get ssh_exchange_identification: read: Connection reset by peer):

    sudo chown root /var/empty