6

In university I normally SSH into the computer sciences server. However today I keep getting the following error: ssh_exchange_identification: Connection closed by remote host. SSHing with -v flags gives me the following.

OpenSSH_5.9p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to ... [...] port 22.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "~/.ssh/id_rsa" as a RSA1 public key
debug1: identity file ~/.ssh/id_rsa type 1
debug1: identity file ~/.ssh/id_rsa-cert type -1
debug1: identity file ~/.ssh/id_dsa type -1
debug1: identity file ~/.ssh/id_dsa-cert type -1
ssh_exchange_identification: Connection closed by remote host

I've tried editing the hosts files but that won't help. Any suggestions?

5 Answers 5

5

This can happen when you have too many different keys to offer. You can easily fix this by adding IdentityFile ~/.ssh/id_rsa_keyname to your ~/.ssh/config entry used for this connection and a global IdentitiesOnly yes. This can look like this:

~/.ssh/config

Host foo
    hostname server.example.com
    User myUserName
    IdentityFile ~/.ssh/id_rsa_keyname

Host *
    IdentitiesOnly yes
8

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.

1
  • 1
    I ran into this issue when upgrading from El Capitan to Sierra. After changing the owner of /var/empty to root (sudo chown root /var/empty/), ssh works like a charm again. Thx!
    – d4Rk
    Commented Oct 25, 2016 at 10:55
8

Little snitch was the problem for me. Rules > Incoming connections

You must do this from the Little Snitch application's preferences.

little snitch allow incoming ssh

2
  • 1
    This description is not helpful. Where in MacOS (what edition of MacOS?) do I go to Rules > Incoming connections ?
    – macetw
    Commented Apr 28, 2017 at 14:09
  • As a matter of fact it is VERY helpful. It clearly says that "Little Snitch [may be the problem]".
    – silverdr
    Commented Jul 17, 2022 at 15:20
1

I just had this issue, and resolved it by going to System Preferences on the Mac, open Sharing, and enable Remote Login.

In my case, I'd been able to access a reverse tunnel for years, but it stopped working after system settings were wiped in a hardware upgrade. This fixed it. Adding the IdentityFile did not.

0

This error can occur due to multiple reasons, in my case it was after upgrading to High Sierra (macOS).

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa

Test:

ssh -vvv  [email protected]

Further reading: https://github.com/jirsbek/SSH-keys-in-macOS-Sierra-keychain

You must log in to answer this question.

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