if yours says network.service then it is wrong - so either something has edited this sshd.service file, or someone else has edited it. And this is the same on both Rocky 8 and 9.
The sshd.service file looks like you say it should. It requires network.target.
But still, when I do systemctl restart sshd
I get the error message Failed to restart sshd.service: unit network.service not found
Any ideas where this could come from?
If it really is related to some legacy config, the first thing would be to think about how and why you’ve got a legacy config, e.g. do you have a pure new Rocky install using official repos, and everything using defaults? if so, this should not be happening.
It is a pure new rocky install. And this used to work, it stopped working after a reboot for no apparent reason. I was assuming that it’s related to some update that happened recently, but I’m not sure. It’s the first reboot in a couple of months.
If it’s this, it can be ruled out very quickly by:
dnf remove network-scripts
since this legacy package can be installed although shouldn’t be by default. This package doesn’t exist in Rocky 9 though.
That said network.service doesn’t exist in this package anyway, so shouldn’t be related to this. I would be more inclined to check for the existence of /usr/lib/systemd/system/sshd.service and check the entire content of this file, and perhaps also do:
find /etc/systemd -iname sshd.service
and check that the results shows a symlink to the /usr/lib/systemd/system/sshd.service file using ls -l, or whether it’s a copy of the sshd.service that may have been edited/played around with.
No packages from doing a dnf repoquery search shows as providing network.service so it sounds like an incorrectly formatted sshd.service file.
Thanks very much for helping me investigate. You were right, there was an unusual modification.
Doing grep -R "network\.service" /etc/systemd, I found that there were additional config files under /etc/systemd/system/sshd.service.d/ which had references to network.service.
I replaced these by network.target and now it works fine.
Yes, that is the place where local customizations are put (for example, when you do systemctl edit sshd.service )
Systemctl does hint about that. Here is a service with default config:
# systemctl status sshd.service
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2022-07-28 18:33:15 EEST; 1 months 15 days ago
And another, with customization by local admin:
# systemctl status krb5kdc.service
● krb5kdc.service - Kerberos 5 KDC
Loaded: loaded (/usr/lib/systemd/system/krb5kdc.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/krb5kdc.service.d
└─override.conf
Active: active (running) since Thu 2022-07-28 18:33:27 EEST; 1 months 15 days ago