Came across this issue on a system I'm rebuilding and spun up a VM running 18.04.3 to test. It seems like I got it working consistently on every reboot. I'll try and breakdown what I've tried and what worked. Everyone & Dev's can let me know if they see any issues of setting it up the way it's working.
First made a backup of the file /etc/systemd/system/sshd.service just in case even though you could use systemctl revert ssh.service to revert any changes.
What I've tried:
editing /etc/systemd/system/sshd.service and changing the following lines from:
What I was trying to see is which service I could have ssh start after seeing as using the various network.service/targets were just not working or consistent. Using whoopsie.service worked the first time I rebooted but each reboot after that ssh failed to start.
I tried the following as well:
systemctl edit ssh.service and putting the above variations in that file and the ssh.service still failed to start.
When looking at:
systemctl show ssh or systemctl show ssh |grep -C 10 "After" to get the data I wanted to see.
I see the following "Before=" argument which has multi-user.target included. When you look at what's in /etc/systemd/system/multi-user.target.wants/ it includes links to ssh.service, networkd-dispatcher.service, networking.service & NetworkManager.service.
Came across this issue on a system I'm rebuilding and spun up a VM running 18.04.3 to test. It seems like I got it working consistently on every reboot. I'll try and breakdown what I've tried and what worked. Everyone & Dev's can let me know if they see any issues of setting it up the way it's working.
First made a backup of the file /etc/systemd/ system/ sshd.service just in case even though you could use systemctl revert ssh.service to revert any changes.
What I've tried:
editing /etc/systemd/ system/ sshd.service and changing the following lines from:
After=network. target auditd.service
to:
After=network- online. target online. target
Wants=network-
or to:
Requires= network- online. target online. target online. target
After=network-
Wants=network-
or to:
Requires= network- online. target auditd.service online. target auditd.service online. target auditd.service
After=network-
Wants=network-
or to:
Requires= whoopsie. service service service
After=whoopsie.
Wants=whoopsie.
What I was trying to see is which service I could have ssh start after seeing as using the various network. service/ targets were just not working or consistent. Using whoopsie.service worked the first time I rebooted but each reboot after that ssh failed to start.
I tried the following as well:
systemctl edit ssh.service and putting the above variations in that file and the ssh.service still failed to start.
When looking at:
systemctl show ssh or systemctl show ssh |grep -C 10 "After" to get the data I wanted to see.
I see the following "Before=" argument which has multi-user.target included. When you look at what's in /etc/systemd/ system/ multi-user. target. wants/ it includes links to ssh.service, networkd- dispatcher. service, networking.service & NetworkManager. service.
Names=ssh.service sysinit. target system.slice -.mount multi-user. target shutdown. target shutdown. target multi-user.target journald. socket network.target sysinit.target -.mount auditd.service basic.target
Requires=
WantedBy=
Conflicts=
Before=
After=system.slice systemd-
From the above data it looks like ssh.service is set to start before multi-user.target?
So I set out to change that behavior:
I tried putting the following in systemctl edit ssh.service which did not work
Requires= multi-user. target shutdown. target user.target user.target
Before=
After=multi-
Wants=multi-
Did systemctl revert ssh.service to revert to the original configs
Then I tried systemctl edit --full ssh.service and put
Requires= multi-user. target shutdown. target user.target user.target
Before=
After=multi-
Wants=multi-
reloaded the daemons systemctl daemon-reload. I don't think it totally necessary to do this if you're going to reboot anyway but why not, no harm.
Rebooted multiple times and now ssh starts on every reboot/boot.