I can't get SSH to work on my newly setup Raspberry Pi 3. Installed a fresh image of Raspbian Stretch Lite.

I am unable to access the machine in the LAN using SSH:

pi@domoticz_pi:~ $ ssh
Connection reset by port 22

The Pi can be pinged succesfully.

Tried the following to get it to work, without any result:

  • Put a empty file called "ssh" (without extension) in the boot partition, using a windows machine (the machine I used to write the image to the SD)
  • Enable SSH with the GUI many times. sudo raspi-config. "Interfacing Options" -> "SSH"
  • Write ssh file to the /boot directory. cd /boot && sudo touch ssh. Reboot the Pi.
  • Restarted the service multiple times: sudo systemctl restart ssh

I don't have a clue why this is not working. Any ideas?

  • 1
    What result do you get if you run on the RPi sudo systemctl status ssh? – Fabian May 10 '18 at 7:46
  • Please edit your question and give us the output from ssh -vvv pi@ – Ingo May 10 '18 at 9:42
  • @Fabian, sudo systemctl status ssh gave me pointers to the cause of the problem. See my answer. – Bram Gerritsen May 11 '18 at 6:32
  • Please add the error messages Could not load host key and key_load_public: invalid format to your question, they are really important and will help other people to find this page in the future. Glad to hear it's solved! – Fabian May 11 '18 at 10:16
  • 1
    So there was a residual key? – Andy Anderson May 11 '18 at 17:03

I have found the solution. See this blog post.

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

| improve this answer | |

You normally start ssh with user@host - on Raspbian pi is the normal user.

Try ssh -vvv pi@host for more diagnostics

| improve this answer | |
  • Yes I know, but get the same error. Thanks anyway. – Bram Gerritsen May 10 '18 at 6:37
  • @Fabian exactly the UID must be the same. You can have same name with different UID. – Ingo May 10 '18 at 9:36
  • @Fabian if you want to chat with Ingo about his irrelevant comment do it in chat. – Milliways May 12 '18 at 9:17

You can also try the below if sudo rm /etc/ssh/ssh_host_* && sudo dpkg-reconfigure openssh-server did not work.

$ sudo su  
# vi /etc/hosts.allow  
$ sudo service ssh restart  
| improve this answer | |
  • 1
    Do you have a reason why you think this might help? – RalfFriedl Mar 11 '19 at 7:10
  • hosts.allow and host.deny are two access control files. When someone tries to connect, access will be provided only if the entered credentials match the one present in hosts.allow file. That is why it should work – Vinuthna V Jul 1 '19 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.