4

Trying to run

systemctl --user start my-service.service

on Ubuntu server 20.04 as a non-root user I get

Failed to connect to bus: Permission denied

Even just

systemctl --user

gives the same error.

The user was created with adduser --disabled-login my-user and is accessed by running su my-user.

Based on what I found researching this issue it seems that some environment variable is not properly initialised when doing su as opposed to "logging in" that causes this.

Show your work:

  • libpam-systemd as suggested here is already installed
  • Setting XDG_RUNTIME_DIR as suggested here did not work
Gecko
  • 356

1 Answers1

2

Your user service is, most likely, not starting because the needed path to the user specific bus socket file at /run/user/$UID/bus(which is part of the user-runtime environment) is not properly set in the environment variable DBUS_SESSION_BUS_ADDRESS ... That should be set to something similar to this:

$ echo "$DBUS_SESSION_BUS_ADDRESS"
unix:path=/run/user/1000/bus

If not set, then set and export it like so:

export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"

Then, try starting your user service again.

Notice: This, however, requires a user-runtime environment which is set mainly by the service user@$UID.service(and company)($UID is the invoking user's ID) ... Which might as well be a culprit in your situation … If it's not running, start it first with sudo(from an administrator user account) (replacing the example 1003 with the actual ID of the user) like so:

sudo systemctl start user@1003.service
Raffa
  • 32,237
  • I started tracing the end user error which lead me to eventually discussing the user-runtime environment at the end of my answer … Now I think I should have written the answer bottom-up :-) … Make sure you read the notice part first. – Raffa May 31 '23 at 13:26
  • 1
    Running sudo systemctl start user@1001.service and adding export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus" seems to have done the trick. Thanks! :D – Gecko Jun 04 '23 at 21:46