Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to 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...
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?

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

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

See before I fixed and after.


ALL: 192.168.1 notice no period after 192.168.1

ssh_exchange_identification: Connection closed by remote host


ALL: 192.168.1. see the extra period after 192.168.1.

fred@'s password:
Welcome to Linux Mint 11 Katya (GNU/Linux 2.6.38-8-generic i686)
share|improve this answer
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 Jul 12 '11 at 0:34
Please note that your answer is a little munged. You should take a look at the formatting. – Stefan Lasiewski Jul 12 '11 at 0:45

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

Change your .ssh/config file


Host * User myusername ProxyCommand ssh nc %h %p


Host *
    User myusername
    ProxyCommand ssh 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|improve this answer

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.

share|improve this answer
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 '11 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 '11 at 5:02
sudo /usr/sbin/sshd -t reports no errors. – rick Apr 7 '11 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 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 '11 at 12:41


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

Please try the command above by regular or root user.

Best of luck.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.