Score:3

Unable to create SystemD user service "Failed to connect to bus: Permission denied"

cn flag

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
hr flag
I'm not really sure how to interpret it, but this seems related [Why isn't a systemd user session started by `su`?](https://unix.stackexchange.com/questions/703410/why-isnt-a-systemd-user-session-started-by-su)
Gecko avatar
cn flag
Looking back at this, running `su --login` instead of just `su` might've also done the trick.
Score:1
jp flag

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 [email protected]
Raffa avatar
jp flag
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.
Gecko avatar
cn flag
Running `sudo systemctl start [email protected]` and adding `export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"` seems to have done the trick. Thanks! :D
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.