ssh_exchange_identification: Connection closed by remote host

34,779

Solution 1

I started getting this error right after I edited by /etc/hosts.allow.

See before I fixed and after.

before

ALL: 192.168.1 notice no period after 192.168.1

ssh_exchange_identification: Connection closed by remote host

After

ALL: 192.168.1. see the extra period after 192.168.1.

[email protected]'s password:
Welcome to Linux Mint 11 Katya (GNU/Linux 2.6.38-8-generic i686)

Solution 2

I know this question is kind of old, but since it doesn't have an accepted answer yet here is the solution that worked for me in the sample case of connecting to a VM machine at Koding.com:

Change your .ssh/config file

from:

Host *.kd.io User myusername ProxyCommand ssh %[email protected] nc %h %p

to:

Host *.kd.io
    User myusername
    ProxyCommand ssh [email protected] nc %h %p

Note 2 things:

  1. 3 lines instead of 1, last 2 lines with 4 spaces as indentation
  2. to avoid the error percent_expand: unknown key %r I changed %r to my username

I am running Centos6

Share:
34,779

Related videos on Youtube

rick
Author by

rick

Updated on September 18, 2022

Comments

  • rick
    rick over 1 year

    Firstly, I know that this question has been asked a million times, and I have read everything I can find and still cannot fix the problem.

    i am encountering this issue when ssh'ing in from my mac to my Ubuntu server on a fresh install of Ubuntu (I reinstalled because of this issue).

    I have SSH portmapped to 7070 because my ISP is blocking 22.

    On the client:

    bash: ssh -p 7070 -v [email protected]
    debug1: Reading configuration data /etc/ssh_config
    debug1: Connecting to address.org port 7070. 
    debug1: Connection established. 
    debug1: identity file /home/me/.ssh/identity type -1
    debug1: identity file /home/me/.ssh/id_rsa type 1
    debug1: identity file /home/me/.ssh/id_dsa type -1
    ssh_exchange_identification: Connection closed by remote host
    

    Here's what I have done to try to resolve the issue:

    Made sure my maxstartups is ok:

    bash: grep MaxStartups /etc/ssh/sshd_config
    #MaxStartups 10:30:60
    
    • Made sure hosts.deny is clear of denials.
    • Made sure hosts.allow has my client IP.
    • Clear out known_hosts on client
    • Changed ownership of /var/run to root
    • Made sure etc/run/ssh is
    • Made sure /var/empty exists
    • Reinstall openssh-server
    • Reinstall ubuntu

    When I run telnet localhost, I get this:

    telnet localhost
    Trying ::1...
    Trying 127.0.0.1...
    telnet: Unable to connect to remote host: Connection refused
    

    When I run /usr/sbin/sshd -t

    Could not load host key: /etc/ssh/ssh_host_rsa_key  
    Could not load host key: /etc/ssh/ssh_host_dsa_key  
    

    When I regenerate the keys with

    ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key  
    ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key  
    

    I get the same error.

    I am pretty sure this is the issue. Can anyone help?

    • NuckinFutz
      NuckinFutz about 13 years
      Is there anything relevant in server:/var/log/auth.log?
    • rick
      rick about 13 years
      "text file busy". should i stop ssh and see it?
    • rick
      rick about 13 years
      stopped sshd, same message.
    • DerfK
      DerfK about 13 years
      it sounds like you're trying to execute the log instead of reading it.
  • rick
    rick about 13 years
    a lot of weird things: ls -l on /home/me/.ssh/ is "total 0". there are no contents of this directory? this is strange. permissions on the keys are right.
  • rick
    rick about 13 years
    sudo /usr/sbin/sshd -t reports no errors.
  • DerfK
    DerfK about 13 years
    @rick if you're using the key on the client at /home/me/.ssh/id_rsa to log into the server, you need to put the contents of id_rsa.pub on the server's /home/me/.ssh/authorized_keys. With only one -v ssh won't tell you everything its doing, but it seems that the server is set up to use keys only instead of passwords, and your key isn't authorized, which could explain why you get disconnected after looking at your keys. Update your question with -vvv instead of -v and read the log on the server.
  • Stefan Lasiewski
    Stefan Lasiewski almost 13 years
    You get a feather in your cap for this one. I've had this same problem. It's hard to debug that little dot sometimes.
  • Stefan Lasiewski
    Stefan Lasiewski almost 13 years
    Please note that your answer is a little munged. You should take a look at the formatting.
  • Michael Hampton
    Michael Hampton over 7 years
    What's the story with that web site?
  • ErichBSchulz
    ErichBSchulz over 7 years
    no association with me! (it just happened to be at the top when I googled) but it goes into more detail - I've been battling this error for an hour then realised I didn't even have ssh on my docker container! none of the existing answers even mentioned it!
  • Michael Hampton
    Michael Hampton over 7 years
    Well that's perfectly normal; you shouldn't have ssh running in a docker container. But we get notified when several answers get posted saying the same thing, so I had to look into it.
  • ErichBSchulz
    ErichBSchulz over 7 years
    yeah - fair enough - although this question was independent of docker - and stumped me for way too long!