environment variable with su - and systemd-run su -
5
votes
1
answer
218
views
If the environment variable DISPLAY is set and I do
`
/bin/su - root
`
from a user shell in an X terminal, then a login shell for root is setup and the DISPLAY environment variable is still present.
If I do
`/usr/bin/systemd-run --quiet --setenv DISPLAY -t /bin/bash -c 'echo "DISPLAY is ${DISPLAY}" ; export DISPLAY=${DISPLAY} ; DISPLAY=${DISPLAY} /bin/su - root'
`
[Yes having both the export and the DISPLAY= before the command is probably overkill.]
then when the login shell for root arrives, the DISPLAY environmental variable is not set, even though it was present and correctly echoed from the systemd-run process before the shell started up. (And I have tried doing --setenv DISPLAY=some_other_value just to check that a distinct value is being passed.)
Testing the complicated
`/bin/bash -c 'echo "DISPLAY is ${DISPLAY}" ; export DISPLAY=${DISPLAY} ; DISPLAY=${DISPLAY} /bin/su - root'
`
on its own just to check that starting the /bin/su -root from a bash command works, the display environmental variable is present in the root login shell.
Omitting the bash invocation and just using /bin/su with the systemd-run command does not work and I include the bash invocation because of the answer to the earlier question
systemd-run does not set environment variables when using --setenv
So why is the DISPLAY not kept when the su login shell is started from systemd-run even though it has been correctly passed to the systemd-run environment with the setenv parameter?
For reference, this is on openSUSE Leap 15.6 with
systemd 254 (254.20+suse.113.gf7f6a3454e).
Asked by J G Miller
(358 rep)
Jan 1, 2025, 08:07 PM
Last activity: Jan 2, 2025, 09:57 AM
Last activity: Jan 2, 2025, 09:57 AM