I log in wish SSH as one user "Ubuntu" on a server. I however want to manage run some systemd services as another user "ABC".
If I try to sudo -u abc bash as user ABC then every systemd --user command gives the error:
Failed to connect to bus: No medium found
I found this thread which suggested adding the following to ~/.bashrc:
export XDG_RUNTIME_DIR="/run/user/$UID"
export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"
This changes the error to:
Failed to connect to bus: No such file or directory
Other sources suggested that headless servers don't normally have dbus installed so this makes sense (it appears to be a component of x11). Though I don't know why it works without issue if I run it as ubuntu.
I found this Suggested Workaround
sudo systemctl -M abc@ --user restart foobar.service
This works for basic start, stop, status but:
systemctl --user catdoesn't work- No variation of
journalctlseems to work:
Failed to open root directory of machine 'abc@': The name org.freedesktop.machine 1 was not provided by any .service files
Failed to open journal: No route to host
- It is just very long to type and inconvenient.
I really just want a shell for this other user just like when I log into ubuntu and can manage all my user services with no issue.
I mention Podman because Podman also is really unhappy when I run it as a different user. It works fine if I use it as ubuntu but get erors if I run it with sudo -u. Like systemd I have some partial workarounds but none seem to work well.