MacOS – How to fix ‘ssh_exchange_identification: read: Connection reset by peer’ on mac OS Mojave

macosmojavesshterminal

I am trying to connect to my Raspberry Pi over ssh using my MacBook.
The command ssh -v pi@ipadress gives the following output:

OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to localhost port 2222.
debug1: Connection established.
debug1: identity file /Users/Nico/.ssh/id_rsa type -1
debug1: identity file /Users/Nico/.ssh/id_rsa-cert type -1
debug1: identity file /Users/Nico/.ssh/id_dsa type -1
debug1: identity file /Users/Nico/.ssh/id_dsa-cert type -1
debug1: identity file /Users/Nico/.ssh/id_ecdsa type -1
debug1: identity file /Users/Nico/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/Nico/.ssh/id_ed25519 type -1
debug1: identity file /Users/Nico/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/Nico/.ssh/id_xmss type -1
debug1: identity file /Users/Nico/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
ssh_exchange_identification: read: Connection reset by peer

I have tried all the answers from other threads but could not get it working. Weirdly though, it works on my iMac without any problems. Is there a way to completely reset all the ssh configurations on my MacBook? I had to recently restore my MacBook from a TimeMachine backup, could it be that the problems come from there?

Best Answer

SSH debugging can be notoriously tricky. I'd start with adding additional -v's to your ssh command to get additional logging from your SSH client.

$ ssh -vv   ...
$ ssh -vvv  ...
$ ssh -vvvv ...

This will return more and more logging from ssh as you add them. The message you're receiving indicates that the server (the peer) is resetting the connection from your ssh client.

This can happen for a variety of reasons one of which is the host is unable to establish (fork) an SSH daemon for your client to connect to. I would suggest rebooting the RPi as a first level of debugging this.

Reference: ssh_exchange_identification: Connection closed by remote host (not using hosts.deny)

It's very likely that this won't be your issue. If it proves not to be there are additional levels of debugging that you can go through to continue to narrow what's causing your issue here.

msg - debug1: Connecting to localhost port 2222

The port you're using to connect is not a standard port, so you might want to investigate if that's intentional or accidental that you're connecting to the SSHD daemon on the RPi is configured to listen on port 2222 or if you're meaning to connect to the RPi via the default port of 22.

References