ssh_exchange_identification: Connection closed by remote host

Today, as I tried to access a server with SSH, I got the following error:

ssh_exchange_identification: Connection closed by remote host

After some searching I found a solution: I have had to add the following line to /etc/hosts.allow:


And voilà, it works.



  1. Posted August 15, 2006 at 5:11 pm | Permalink

    Warning: that line will allow SSH access from any IPv4 address and there are a lot of scanners out there (machines which just try to guess logins with brute force). If you can, only put hosts, domains or networks which you want to have SSH access in there.

  2. Posted August 16, 2006 at 7:57 am | Permalink

    @MJR/slef: Thanks for the warning, I changed it. Is it also an issue if a NAT device is used?

  3. Posted August 16, 2006 at 8:59 am | Permalink

    A NAT device can limit your checks: you can either allow or disallow connections which appear to be from the NAT device. Then again, most NAT devices I have seen can do firewalling too, so that’s not a major problem. Just another place to set access control…

  4. Posted September 26, 2006 at 5:40 pm | Permalink

    You’re better off looking at using DenyHosts ( as it will block known SSH boots.

    Also add your own IP to /etc/hosts.allow in the form of IP addr/Netmask.

    I also restrict password login in SSH and use shared keys. :) Avoids the problem with burte force password attacks.

  5. Posted September 27, 2006 at 1:55 pm | Permalink

    @Strider: Thanks for the tips :)

%d bloggers like this: