Comment 33 for bug 216847

Revision history for this message
nimish (nimishp12) wrote :

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
Wants=network-online.target

or to:

Requires=network-online.target
After=network-online.target
Wants=network-online.target

or to:

Requires=network-online.target auditd.service
After=network-online.target auditd.service
Wants=network-online.target auditd.service

or to:

Requires=whoopsie.service
After=whoopsie.service
Wants=whoopsie.service

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
Requires=sysinit.target system.slice -.mount
WantedBy=multi-user.target
Conflicts=shutdown.target
Before=shutdown.target multi-user.target
After=system.slice systemd-journald.socket network.target sysinit.target -.mount auditd.service basic.target

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
Before=shutdown.target
After=multi-user.target
Wants=multi-user.target

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
Before=shutdown.target
After=multi-user.target
Wants=multi-user.target

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.