Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

SSH "connection closed" instantly

Alright, I have a feeling this is my own doing as a few months ago I was experimenting with public/private key authentication. Now I can't SSH into one of my work computers. That is, no machine can SSH into it and it can't SSH into itself.


When I run the command


ssh [myusername]@localhost


from the machine in question, I get:


Connection closed by ::1


Now, when I run


ssh -vv [myusername]@localhost


I get:


OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009
debug1: Reading configuration data /etc/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /Users/pro01/.ssh/identity type -1
debug1: identity file /Users/pro01/.ssh/id_rsa type -1
debug1: identity file /Users/pro01/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.2
debug1: match: OpenSSH_5.2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
Connection closed by ::1


I've tried searching around but haven't had any luck. Anyone have any ideas as to how I can fix this and get my SSH working again?

Mac OS X (10.6.7)

Posted on Apr 20, 2011 8:53 AM

Reply
10 replies

Apr 20, 2011 12:41 PM in response to JeffMurchison

It would appear the server is killing your connection.


Is the Firewall enabled? try disabling it.


Look in /var/log/secure.log to see if sshd is issuing any useful information.


You can change the sshd debugging level into /var/log/secure.log using


/etc/sshd_config


adding


LogLevel DEBUG3


Then stop/start System Preferences -> Sharing -> Remote Login


What might be helpful in analyzing the DEBUG3 output is to do the same thing to a working system, and then compare the /var/log/secure.log output and see where the login sessions differ.

Jan 9, 2012 5:25 PM in response to JeffMurchison

Alright, so funny enough I stumbled upon this thread when I encountered the same issue on another computer. This thread was the top result on Google.


I did a bit of poking and prodding, looking at the console and logs and verbose output and I figured it out. I figured I would add the answer here in case anyone else has the same issue.


The problem was permissions on the file


/etc/ssh_host_dsa_key


were set to 777 when they should have been set to 700.


Running the following command fixed the issue:



sudo chmod 700 /etc/ssh_host_dsa_key

SSH "connection closed" instantly

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.