Can one user, or maybe root, control another user's user level systemd services?I've tried sudo -u <some user> systemctl --user restart <some service>, but it complains about dbus: Failed to get D-Bus connection: Connection refused.
Managing another user's systemd units
sudo;systemd
I had the same problem when I remotely logged into my gentoo box via ssh. In my case this was because the XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS environment variables were missing. Run the following commands and try again:export XDG_RUNTIME_DIR=/run/user/$UIDexport DBUS_SESSION_BUS_ADDRESS=unix:path=${XDG_RUNTIME_DIR}/busIf this helps, you can put those commands into your .bashrc. I guess there must be a more elegant solution than .bashrc but that depends on your distro.Here is where I found that solution.Edit:logged in as root, I managed to successfully run systemctl --user as another user using su as follows:su -c 'XDG_RUNTIME_DIR=/run/user/$UID DBUS_SESSION_BUS_ADDRESS=unix:path=${XDG_RUNTIME_DIR}/bus systemctl --user status' usernameor using sudo (note, I had to explicitely add the respective users UID (1000) to the path '/run/user/'):sudo -u username XDG_RUNTIME_DIR=/run/user/1000 DBUS_SESSION_BUS_ADDRESS=unix:path=${XDG_RUNTIME_DIR}/bus systemctl --user status