Who copies the DISPLAY and XAUTHORITY variables when using sudo?

They are not specified in the env_keep option in /etc/sudoers, but are exported.

declare -p DISPLAY XAUTHORITY    # display variables as normal user 
sudo -i
declare -p DISPLAY XAUTHORITY    # display variables as sudo'ed user

i’m currently using the admin:// method on sway.
i think on gnome & xfce it was pkexec.
when using sudo it’s normally with nano for me.

If I look at the archlinux PKGBUILD for sudo, I do not see –disable-env-reset, which I think controls whether environmental variables are passed or not.

The archlinux sudo wiki page says

The recommended way of preserving environment variables is to append them to env_keep

If I explicitly set Defaults env_reset and I do not have an env_keep, what is passing DISPLAY and XAUTHORITY when I use sudo?

This is more of an educational question after much research. :thinking:

After reading archwiki, the man pages for sudoers and pam_env, etc, and the sudo mailing list, I think I got it. When using sudo, the preserved environmental variables are hard-coded.

These can be viewed by

sudo -i
# followed by
sudo -V

Distro’s can vary, so a script may work on one distribution but not another.

If anyone has anything to add, I’m all ears :ear:

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.