3

I suddenly can't connect to my Raspberry Pi from my laptop. In Terminal, I try to access with the command ssh pi@192.168.XX.XXX and I get this message:

ssh_exchange_identification: read: Connection reset by peer

I have searched for answers but nothing works:

  1. sudo rm /etc/ssh/ssh_host_* didn't result in anything..
  2. sudo dpkg-reconfigure openssh-server gave: sudo: dpkg-reconfigure: command not found
  3. ssh -vv pi@192.168.XX.XXX gave:

    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 *
    debug2: resolve_canonicalize: hostname 192.168.XX.XXX is address
    debug2: ssh_connect_direct
    debug1: Connecting to 192.168.XX.XXX [192.168.XX.XXX] port 22.
    debug1: Connection established.
    debug1: identity file /Users/peterwesterlund/.ssh/id_rsa type -1
    debug1: identity file /Users/peterwesterlund/.ssh/id_rsa-cert type -1
    debug1: identity file /Users/peterwesterlund/.ssh/id_dsa type -1
    debug1: identity file /Users/peterwesterlund/.ssh/id_dsa-cert type -1
    debug1: identity file /Users/peterwesterlund/.ssh/id_ecdsa type -1
    debug1: identity file /Users/peterwesterlund/.ssh/id_ecdsa-cert type -1
    debug1: identity file /Users/peterwesterlund/.ssh/id_ed25519 type -1
    debug1: identity file /Users/peterwesterlund/.ssh/id_ed25519-cert type -1
    debug1: identity file /Users/peterwesterlund/.ssh/id_xmss type -1
    debug1: identity file /Users/peterwesterlund/.ssh/id_xmss-cert type -1
    debug1: Local version string SSH-2.0-OpenSSH_7.9
    ssh_exchange_identification: read: Connection reset by peer
    
  4. sudo rm /etc/ssh/ssh_host_* gave: rm: /etc/ssh/ssh_host_*: No such file or directory

  5. lsof -n | grep ssh | grep DEL didn't do anything

I'm not very good or comfortable with command lines. So I don't really know what things above mean but I found those things when I searched for solutions online.

Edit: On request, here is the list of devices connected to my network and you see my Raspberry Pi/Hassbian there: enter image description here

  • First question - are you sure you have the IP address on the Pi correct and you are not linking back to your laptop? You can put the full IP address of internal networks on the internet safely as we cannot access them and it really helps debugging. –  Apr 13 '20 at 18:44
  • @Andyroo Okay, I have now edited my original post with an image of the devices to my network where you can see my Raspberry Pi/hassbian. – Peter Westerlund Apr 13 '20 at 20:37
  • Going by https://github.com/home-assistant/hassio-addons/blob/master/ssh/README.md you need to add an add-on to enable ssh. If you can get into the Pi locally, then the auth.log should give a clue. It maybe worth clearing the local machines ssh keys for the machine and IP address. –  Apr 13 '20 at 21:02
  • @Andyroo But I have been able to connect the other day. So why would ssh become disabled by itself suddenly? It's quite a project for me to get into the Pi locally since I don't own an external keyboard and mouse. I remember when I installed the Pi that I borrowed from friend and family. But if that's my only option then I guess I have to. – Peter Westerlund Apr 13 '20 at 21:13
  • possible change of IP address to another one that had a Pi on it? I now try and avoid IP address based SSH and only use the name then it’s a simple hack to remove the raspberry pi entry in the ssh file. What machine are you using to connect to the Pi? If it’s a Mac then the file can be edited from the terminal using nano - it’s hidden away in ~/.ssh off the top of my head. –  Apr 13 '20 at 21:51
  • @Andyroo I'm not sure I understand. But no it's the same IP address as before. But even ssh pi@hassbian get the same message. I'm on a Macbook Air, so yes Mac. I don't understand what you are saying that I could do. I'm not familiar with that file, I'm not that comfortable with command lines. What command should I run? – Peter Westerlund Apr 13 '20 at 22:17
  • It's quite a project for me to get into the Pi locally - so how did you run all those commands? – Jaromanda X Apr 13 '20 at 22:55
  • On the Mac open a terminal session. Enter nano .ssh/known_hosts and see if the list has an entry for the name or IP address. If so use the cursor key to move to the line and press ctrl-k (not cmd key). Repeat as needed and then press ctrl-x and save the file as the same name if you deleted any line. Then try again. –  Apr 13 '20 at 23:12
  • You admit "I don't really know what things above mean" but then attempt "sudo rm /etc/ssh/ssh_host_*" - fortunately for you because no such file exists, but randomly deleting files you don't understand is unlikely to improve the situation. – Milliways Apr 14 '20 at 00:14
  • @JaromandaX It didn't say anywhere that it should been done ON the raspberry. I mean what I'm trying to do is to connect to the raspberry from my computer. So I don't even understand why I would try to access something if I were connected to it from the beginning. – Peter Westerlund Apr 14 '20 at 13:27
  • @Andyroo I didn't find the IP in that list. – Peter Westerlund Apr 14 '20 at 13:28
  • @Milliways Well I understand what the command do, that it deletes all the files that begins with "ssh_host_". And I would guess it has to do with my problem since it is about ssh. But no, I didn't know such a file existed and I don't know much about the backend of ssh. So yes, a little bit of risktaking here. But since I'm stucked, I kind of have to. – Peter Westerlund Apr 14 '20 at 13:31

2 Answers2

3

As far as I can see from the extended logging of the ssh connection you are only using key file authentication, but no password authentication. That is good for improved security. But the ssh client tries to find a valid identity file in /Users/peterwesterlund/.ssh/, but all possible identity files are quit with -1, that means not found. It seems you have lost your private identity key file on the client, or it is moved to another location, or you had password authentication and on the ssh server it was disabled.

Ingo
  • 42,107
  • 20
  • 85
  • 197
  • To check if you still have any keys on the Mac go into the terminal and use the command ls .ssh/ and you should see id_rsa and id_rsa.pub files along with known_hosts. If not you can regen them by issuing the command ssh-keygen -t rsa - DO NOT use a password else you will have to enter it each time! Send this over to the Pi with ssh-copy-id pi@xxx.xxx.xxx.xxx and use the Pi password IF IT LETS YOU. –  Apr 14 '20 at 14:59
2

Actually I solved the problem by just break the power from the Raspberry Pi and then power it on again and then connect with ssh.

  • 4
    I came to this thread because after the SSH connection hangs and won't reconnect, I'm forced to kill the pi, but this seems like an extremely poor solution to the problem. – ggorlen Jan 21 '21 at 17:14
  • I tried this and it worked! Now I'm left wondering what breaks sshd in the first place ... – samvv Mar 16 '24 at 11:46