XDG_RUNTIME_DIR
is necessary for systemctl --user
to work.
I have set up ubuntu server 16.04 to run systemd user sessions. Now, when trying to administer them, I find that when changin a user via sudo -u $user -i
or even su - $user
, the environment does not have XDG_RUNTIME_DIR
set, preventing systemctl --user
from working. However, when I ssh
straight into that user, it is set correctly.
If I understand the documentation correctly, this should be set by libpam-systemd
when creating the user session. The user slice is started correctly, as the directory to which XDG_RUNTIME_DIR
should point(/run/users/$uid
) exists. I'm hesitant to just hardcode it in, say, .bash_profile
, because that seems hacky (albeit working), when pam should be taking care of it.
I can, of course, add XDG_RUNTIME_DIR
to env_keep
in sudoers
, but that would just preserve the sudoing user's environment, which is not what I want. I want the target user's environment.
What I'm really wondering, though, is how come the session is set up correctly with ssh
, but not with su
or sudo -i
?