Can’t ssh to Raspberry Pi

Intro
I did not experience this problem but it happened to a friend of mine – more than once. I’m not sure what he’s doing during installation of the OS to cause this but I know the solution.

Also there is some really misguided information out there on the Internet. Pure ignorance talking. There’s some accurate discussion as well. By re-posting correct information I hope to increase the average correct treatment. I have nothing original to say per se.

The details
The problem is that you can”t log in to your Raspberry Pi via ssh. See if the ssh daemon is running:

$ sudo service ssh status

sshd is running.

Probably it is and you see the response above.

Try to log in locally:

$ ssh localhost

If you get something like this:

Read from socket failed: Connection reset by peer

then you have the problem which can be fixed by this procedure below.

The fix

$ sudo dpkg-reconfigure openssh-server

Or more generally:

$ sudo rm /etc/ssh/ssh_host_* && sudo dpkg-reconfigure openssh-server

There must be some way to screw up the Raspbian installation that produces this particular problem.

And all this is assuming you already had the presence of mind to enable ssh in raspi-config. That of course is a prerequisite.

Conclusion
You should be able to ssh (remote shell access) to your Raspberry Pi. If you cannot the recipe above is probably the needed fix. This discussion is generally valid for all Debian installations, except for the comment about raspi-config!

References
The correct discussion on this topic in the official Raspberry Pi forum is here.
I’ve published quite a few articles now on Raspberry Pi.
A digital photo frame is described in this article.
Using a Raspberry Pi as a router is described here.

This entry was posted in Admin, Raspberry Pi. Bookmark the permalink.

10 Responses to Can’t ssh to Raspberry Pi

  1. Tyee Cambron says:

    The solution is finally found! Maybe…

    But I already gave up and I am running my pi security cam video streams on ethernet cable to a dlink dss-16+ switch and to ethernet laptop.

    The problem was that I couldn’t ssh to the pi with the pi connected on wifi. But I could ssh to it if it was connected on ethernet cable. I spent hours in the search engine and reading useless post.

    • Tyee Cambron says:

      Oh wait, now I remember… I wasn’t able to ping the pi or even connect to port 80 if the pi was on wifi.

      Pi on Wifi: I can browse the internet on the pi. Can’t ping pi from other wifi-connected devices. Port scan from PC to Pi shows no open ports. And yes, I had ip address correct as listed on router-lan-devices and pi-ifconfig.

      Pi on ethernet: I can browse the internet on the pi. Able to ping pi from Wifi-devices. Port scan shows http and ssh ports open.

      Similar problem with both of my android phones. I can’t ftp to local network servers or remote to the android. Which I was able to do some time ago last year. (router firewall is off)

  2. Thanks for these suggestions. However, I cannot SSH into my Pi from other devices. My Pi is connected on WIFI, and I have a Google Subdmain registered, which I am updating through DDCLIENT. I am honestly lost as to why I cannot SSH into it.

  3. jj says:

    Oh my, thank you so much for this post. I was getting a bit frustrated.

  4. Rahul Modi says:

    if you have IP address of RPi and you are able to ping it then probably the issue is SSH is disabled for your RPi. The RPi released in/after Nov 2016 having SSH by default disabled. To enable SSH refer this video : https://www.youtube.com/watch?v=zKT6bTESlLs

  5. mike diaz says:

    I was hopeful, but the dpkg fix didn’t work for me. I’m able to SSH into my Pi from the local net at home, but when I try to SSH remotely with port forwarding, I get a refused connection. I can also SSH to the remote computer from my Pi. The port forwarding is OK because I have no problem connecting to my Pi remotely with rdesktop. Suspect it’s an issue with my sshd_config…

    • john says:

      Hmmm. Not sure. But I’m a little suspicious of your port forwarding. Perhaps try a different port, like 22222. I would also run a tcpdump on your Pi to see if it sees any of the ssh packets – I suspect it doesn’t. Or maybe you’re running iptables (kind of firewall) on your Pi and don’t even know it!

  6. Tom says:

    You, sir, are a gentleman and a scholar. Spent ages trying to get SSH working on my RetroPie build without success. This resolved the problem in seconds. Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *


4 + one =