Mohammedz.com

For Linux and Shell scripting.

ssh_exchange_identification: Connection closed by remote host

8 Comments


While trying to logging into a Linux machine you may get the error:
ssh_exchange_identification: Connection closed by remote host

At the same time, you may be able to login to this server from some other machine.

The most common reason for this error is, the machine from where you are trying to login is not allowed to access the server. Means, your local machine is not listed in /etc/host.allow file of the server.

So, please check the following files on the server (you will have to login to the server from a machine which is allowed to access the server. Or else you should contact someone who can do it for you ;))

/etc/hosts.allow
/etc/hosts.deny

If you are not sure what should be listed in the /etc/hosts.allow, add the following line to it (and comment all other lines, if it’s not already)

SSHD: ALL
This entry will allow SSH access from anywhere.

By default, there won’t be any entry in /etc/hosts.deny file

Advertisements

8 thoughts on “ssh_exchange_identification: Connection closed by remote host

  1. Thank you so much.
    That’s why I couldn’t login to a windows box running openssh from Cygwin

  2. THANK YOU so much! Been a while since I have done linux administration, and this is why I couldn’t login from my home IP.

  3. Thanks – got me unstuck. (I was so sure I had those files right too).

  4. Thanks!
    Hosts.allow had two entries. The first was:

    ALL : PARNOID : deny

    the second was:

    sshd: ALL

    Of course the first one triggered for everything. Change the order of the two lines and we are back in action.

  5. Gracias desde Argentina!!! tenia invertidas las líneas del archivo /etc/hosts.allow como dijo John. Ahora todo funciona bien.

    Thanks from Argentina!! i’ve changed the order of the two lines in the /etc/hosts.allow file as John said. Now everything works fine!

  6. If you can it’s better to use something like

    sshd: ip.add.ress.1, ip.add.ress.2, …

    rather than a blanket

    sshd: ALL

    so that only the IP addresses that you specifically allow can attempt to use ssh to connect to the box.

  7. I was in an assumption that “ssh_exchange_identification: Connection closed by remote host” error is caused only because of the SSH restriction through /etc/hosts.allow and /etc/hosts.deny files. Today, I found a permission issue which caused same error.

    When I checked the server with a console, I found the SSH keys with wrong permissions. The SSH will fail if the private keys have world readable/writable permissions. The permissions should be like:

    ***************************
    # ls -l /etc/ssh/
    -rw——- 1 root root 125811 2008-10-17 02:06 moduli
    -rw-r–r– 1 root root 1964 2008-10-17 02:06 ssh_config
    -rw——- 1 root root 3715 2009-06-12 02:23 sshd_config
    -rw——- 1 root root 3717 2009-06-12 02:21 sshd_config.bak
    -rw——- 1 root root 668 2009-06-09 22:36 ssh_host_dsa_key
    -rw-r–r– 1 root root 590 2009-06-09 22:36 ssh_host_dsa_key.pub
    -rw——- 1 root root 963 2009-06-09 22:36 ssh_host_key
    -rw-r–r– 1 root root 627 2009-06-09 22:36 ssh_host_key.pub
    -rw——- 1 root root 1675 2009-06-09 22:36 ssh_host_rsa_key
    -rw-r–r– 1 root root 382 2009-06-09 22:36 ssh_host_rsa_key.pub
    #
    ***************************

    Also, SSH service won’t start if /var/empty/sshd has wrong permission. It’s permission should be 711.

    ***************************
    # ls -l /var/empty/
    drwx–x–x 2 root root 4096 2008-10-17 02:06 sshd
    ***************************

    ~mohammed

  8. Thanks,

    The strange thing was that on some PC’s it was OK and not on others. It has drived me crazy for a while. Now that I changed the sequence of the two entries on all PC with Cygwin, it works consistently.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s