This is a remote machine with SSH access and systemd.
I basically have this error when I try to run systemd user commands:
$ systemctl --user status Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user)
While other answers suggest to just set or "fake" the requested variables IMHO, this is not a proper solution.
The problem is basically that I logged in as a one user (I use as a system admin) and I did switch the user via
su. As such, it's very much understandable systemd does not have a clue what user I'm running here…
So I understand it is confused.
Note while for systemd services maybe using the system bus is maybe the better idea altogether.
However, for experimenting with podman and especially
podman generate systemd also wants a user-level session, maybe just having a lingering user (
loginctl enable-linger) is a useful way.
Now the actual question: How can I switch to the other user, so that systemd really knows that this user is now logged in? I just want to "operate" as a different user (in a new shell). Just as if I would use
Note that I do not want to SSH into the server as another user. That requires additional SSH keys and other stuff that is just not necessary. I want to switch my user while being logged in (as a user that can run
sudo, i.e. system admin).
sudo machinectl login, but that is:
- inconvenient, as I need to type the username again in there (I cannot do
sudo machinectl login my-user.
- a problem, as my user is a system user just for podman and I don't have a password set – so I cannot login with a password
machinectl shell, which sounds exactly what I want to do, but I cannot get it to work.
machinectl shell my-user and
machinectl shell my-user@localhost, but it always just tells me:
Failed to get shell PTY: No machine 'localhost' known
Well… note that it also shows me I have no "machines" (whatever these are? Is not
$ machinectl list No machines.