ssh error: connection closed by remote host

When trying to SSH into a particular Mac machine it gives me the following error :

ssh_exchange_identification: Connection closed by remote host

I have done some google searches on the issue but I haven't seem to find a definite answer. I did notice that on the machine that I am trying to SSH into, it does not have the ~/.ssh file even on there so I went ahead and created it and gave it correct permissions but that didn't help. Here is the verbose of when attempting to SSH into it:

penSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to <ComputerName> [xxx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /Users/<UserName>/.ssh/id_rsa type 1
debug1: identity file /Users/<UserName>/.ssh/id_rsa-cert type -1
debug1: identity file /Users/<UserName>/.ssh/id_dsa type -1
debug1: identity file /Users/<UserName>/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
ssh_exchange_identification: Connection closed by remote host

Any ideas on how to get SSH working?


Solution 1:

I ran into this same exact issue. My system log reflected:

/var/empty must be owned by root and not group or world-writable

Going to Disk Utility > Macintosh HD > Repair Disk Permissions reset the permissions of /var/empty and solved the problem for me.

Solution 2:

Does the Mac you want to ssh into have sshd turned on and the right user permissions?

under system preferences> sharing >

turn on remote login and remote management and then select the users you want to allow to ssh into the machine.

if yes, tail the /var/log/system.log to get more info