Start SSH automatically on boot

Have you tried just simply setting

sudo systemctl enable ssh

?

That's how I have my ssh set to run at start up.

****I'm leaving in the above part of the answer in case it's helpful for others who come across this post****

Quoting my comment from above:

How do you have your port forwarding setup? I don't use the ListenAddress at all and things work fine on my home server. My router forwards anything that comes in on a port I specify (22 if you want the standard port, but you can use anything as long as it doesn't conflict with other services on your intl. network) to the computer I want. For example anything that comes in on port 12345 gets forwarded to port 22 on my CentOS server. Anything that comes in on 12346 gets forwarded to port 22 of my headless RasPi. Anything that comes in on 12347 goes to port 6697 for the IRC bouncer on my RasPi

The ListenAddress has nothing to do with port forwading, the ListenAdress can be used for a server that is configured with multiple IP addresses over one or more NICs. Quoting from here (the whole page is a good explanation): https://www.cyberciti.biz/tips/howto-openssh-sshd-listen-multiple-ip-address.html

Let us say you have total 8 public IP address and one private IP address. You >would like to bind sshd to one selected public IP (ex 70.5.xx.xx) and private >IP (10.1.5.1) only.

Luckily there is an easy way to achieve this using ListenAddress option. It >specifies the local addresses sshd should listen on. If this directive is >skipped from configuration file sshd will bind or list on all available IP >address.

It's to allow one some of your multiple IPs to accept ssh connections. I'm guessing you set the ListenAddress to either your public IP or your router's internal IP - I'm guessing if you set that to your server's local IP it would have worked fine. Regardless, now you know how ListenAddress works and you'll be ready if you have to configure a more complicated server. Glad to hear you got things working.


As the suggested solution did not work for me, I eventually found that additional command is needed to start SSH on boot:

sudo update-rc.d ssh defaults
sudo systemctl enable ssh.socket

Some mentioned that this command:

sudo systemctl enable ssh.service

should be executed instead of this command:

sudo systemctl enable ssh

Tags:

Ssh

Openssh

16.04