I did a fresh installation of Ubuntu Mate on my Raspberry Pi 2.

Installed openssh-server (in fact it was already installed), and changed the port to be 10022.

However, I cannot access the Pi, from the netowork, neither from the same machine (the Pi itself):

$ ping 
PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=165.807 ms
64 bytes from icmp_seq=1 ttl=64 time=257.509 ms
64 bytes from icmp_seq=2 ttl=64 time=170.881 ms
64 bytes from icmp_seq=3 ttl=64 time=1.686 ms
--- ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.686/148.971/257.509/92.516 ms
$ ssh -p 10022
ssh: connect to host port 10022: Connection refused

How to solve this? Why does it appear?

On a different machine, connected on the same network and everything works fine.

  • Did you restart the SSH Daemon after changing the port? Aug 11, 2019 at 11:35
  • @SteveRobillard I restarted the pi... Aug 11, 2019 at 12:07
  • What is the ouput of systemctl status ssh sshd. If it's not enabled run sudo systemctl enable --now ssh*.
    – jake
    Aug 11, 2019 at 13:23
  • @jake They both are enabled but they say cannot load host key .... Aug 11, 2019 at 14:13
  • @jake That was useful to debug -- I ran sudo dpkg-reconfigure openssh-server (to regenerate the host keys) and then rebooted and it works now. I assume somehow these keys were not there after the installation. You can post an answer if you like. Aug 11, 2019 at 14:20

3 Answers 3


To troubleshoot your problem run systemctl status ssh. You can see from the output if the ssh server is running and enabled and also see the most recent lines from the log.

journalctl -e -u ssh.service could also be helpful to find the issue. It will show everything logged regarding the specified unit.

As we clarified in the comments you found following error cannot load host key which could be solved by regenerating the host key file: sudo dpkg-reconfigure openssh-server.


The SSH is not enabled in your raspberry pi. Access the root directory of SD card and create a file named “ssh” with no extension and back into you pi and reboot. This should tell you pi to enable ssh.

  • 1
    That is true for Raspbian, but is it true for Ubuntu? Aug 11, 2019 at 11:36
  • Nick, I tried that, but unfortunately it does not make any change... Aug 11, 2019 at 12:07
  • 1
    This answer should be removed because it ignores the context of the question. Also, there's no such thing as "the root directory of SD card". Aug 14, 2019 at 7:19

Sorry didn't notice that you had Ubuntu Mate on your raspberry pi. Have you tried the following commands to reinstalled openssh-server.

sudo apt-get remove openssh-server
sudo apt-get install openssh-server
# I rebooted system after install
sudo systemctl enable ssh


  • Please don't make a new answer. Instead edit your first answer and correct it.
    – Ingo
    Aug 13, 2019 at 7: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.