8

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?

4
  • Is there anything relevant in server:/var/log/auth.log? Apr 7, 2011 at 1:58
  • "text file busy". should i stop ssh and see it?
    – rick
    Apr 7, 2011 at 5:00
  • stopped sshd, same message.
    – rick
    Apr 7, 2011 at 5:03
  • 3
    it sounds like you're trying to execute the log instead of reading it.
    – DerfK
    Apr 7, 2011 at 12:34

5 Answers 5

6

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)
2
  • 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. Jul 12, 2011 at 0:34
  • 1
    Please note that your answer is a little munged. You should take a look at the formatting. Jul 12, 2011 at 0:45
3

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

0

The most likely thing I can think of that would bail out where you were that you didn't already say you checked would be ownership of your authorized_keys file. Check that /home/me/.ssh/ is 700 and the files inside are 600 (not group accessible) and owned by "me". Try -vvv for a more detailed explanation of what exactly ssh is doing at that point.

Be sure you're running sshd -t as root. I get that "can't open host key" error if I run it as a user. Otherwise, make sure /etc/ssh/ssh_host_*_key is root:root and 600, but the .pub keys are root:root 644

I think selinux would have griped about the nonstandard port before you were even able to connect to it, but just in case, check /var/log/audit.log if selinux is enabled.

4
  • 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
    Apr 7, 2011 at 5:00
  • what should be in this directory? this has to be it. but re-installing sshd doesn't seem to change anything... should i do it again?
    – rick
    Apr 7, 2011 at 5:02
  • sudo /usr/sbin/sshd -t reports no errors.
    – rick
    Apr 7, 2011 at 5:08
  • @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.
    – DerfK
    Apr 7, 2011 at 12:41
0

how_to_generate_keygen:

$ ssh-keygen -t dsa -P “” -f ~/.ssh/id_dsa

Please try the command above by regular or root user.

Best of luck.

0

You can get "ssh_exchange_identification: Connection closed by remote host" if your sshd service is not operational!

If you have access to the server check you have the sshd service running with:

  ps aux | grep ssh

and check it is listening on port 22:

 netstat -plant | grep :22

more details here

4
  • What's the story with that web site? Jan 21, 2017 at 5:53
  • 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! Jan 21, 2017 at 5:55
  • 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. Jan 21, 2017 at 6:00
  • yeah - fair enough - although this question was independent of docker - and stumped me for way too long! Jan 21, 2017 at 6:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .