Cannot use `systemctl –user` due to "Failed to get D-bus connection: permission denied"

xenoid asked:

I’m trying to set up user-level services, using this answer to a similar question. I have create the required files and rebooted.

I’m making progress because I now get “Failed to get D-bus connection: permission denied” when it was “Failed to get D-bus connection: connection refused”, but I’m stumped because I don’t know what object it is trying to access (file? socket?) and so cannot even check current permissions. Any ideas?

So far I have added:

loginctl enable-linger userservice

/usr/lib/systemd/user/dbus.service (-rw-r–r– root root)

Description=D-Bus User Message Bus

ExecStart=/usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation
ExecReload=/usr/bin/dbus-send --print-reply --session --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig


/usr/lib/systemd/user/dbus.socket (-rw-r–r– root root)

Description=D-Bus User Message Bus Socket

ExecStartPost=-/bin/systemctl --user set-environment DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus



Description=Test user-level service



Not added any links elsewhere…

To make it fail:

systemctl --user status

Using RHEL 7.4 (systemd 219) with SELinux.

My answer:

So there’s a long standing issue where the XDG_RUNTIME_DIR environment variable doesn’t get set properly, or at all, when users log in, and therefore can’t access the user D-Bus. This happens when the user logs in via some other method than the local graphical console.

You can work around this by adding to the user’s $HOME/.bashrc:

export XDG_RUNTIME_DIR=/run/user/$(id -u)

Then log out and back in.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.