So this question has been already asked, but the answers there do not solve the issue of environment variables. Is there a way to be switch users completely such that the pam-systemd
is called and every automatic XDG environment variable is set?
Compare the following
The following options start by turning on a powered down machine.
Option 1 Log in as root. Type the following within the shell:
su -l username
echo $XDG_RUNTIME_ENV
Option 2 Log in as username. Type the following within the shell:
echo $XDG_RUNTIME_ENV
You see that there is a difference. Option 1 yields /run/user/0
despite the change in users using su
(switch user), because the pam_systemd
module was not called during the switch. Option 2 yields /run/user/$(id -u)
as expected. Now I could simply log off by typing exit
until the machine prompts me for a login again and login as the desired user. Is there another way to do it? Using sudo
instead of su
does not help.
Is it the right way to do echo "XDG_RUNTIME_DIR=$(id -u) >> .bash_profile"
, because .bash_profile
gets executed by su
?