SystemD User Manager – Fix Service Failure on Ubuntu

linuxsystemdUbuntu

I am running a bunch of Ubuntu 20.04 vServers for my company. They have a regularly appearing problem, being that the user manager service for the SSH User ([email protected]), sometimes fails when I log in using SSH.

The only common denominator these servers have is that they are all running Apache servers, an Icinga monitoring service and a daily backup to s3, and that they run with the same hosting company. What gives me the most headache however is, that this doesn't happen consistently, you might log in 10 times without the service failing, also it is not happening on all of the servers.

In the syslog I found the following:

Failed to create /user.slice/user-UID.slice/[email protected]/init.scope control group: Permission denied

I found a post suggesting to give rwx to the group on the directory the file is created in.

sudo chmod o+rwx -R /sys/fs/cgroup/systemd/

However this is only a temporary solution and does not survive reboots.

My best guess as to why it happens so inconsistently would be, that some of the servers are compromised, however I haven't found any indicators to this conclusion.

Maybe some of you have ever experienced something similar?

Best Answer

As it turns out the provider left a config file in /etc/systemd/system/[email protected]/ setting the Delegate option to no, changing it to yes resolved the problem. Because of this option, systemd did not change the ownership of the directory the user manager tried to create files in to the user, hence the permission to create files didn't exist.