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
    Commented May 10, 2018 at 7:46
  • Please edit your question and give us the output from ssh -vvv [email protected].
    – Ingo
    Commented May 10, 2018 at 9:42
  • @Fabian, sudo systemctl status ssh gave me pointers to the cause of the problem. See my answer. Commented May 11, 2018 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
    Commented May 11, 2018 at 10:16
  • 1
    So there was a residual key? Commented May 11, 2018 at 17:03

3 Answers 3


I have found the solution. See this blog post.

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


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

Try ssh -vvv pi@host for more diagnostics

  • Yes I know, but get the same error. Thanks anyway. Commented May 10, 2018 at 6:37
  • @Fabian exactly the UID must be the same. You can have same name with different UID.
    – Ingo
    Commented May 10, 2018 at 9:36
  • @Fabian if you want to chat with Ingo about his irrelevant comment do it in chat.
    – Milliways
    Commented May 12, 2018 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  
  • 1
    Do you have a reason why you think this might help?
    – RalfFriedl
    Commented Mar 11, 2019 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
    Commented Jul 1, 2019 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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