To get DISPLAY and XAUTHORITY this requires some tricky bash environment which depends on the display manager as well as on the sudo configuration. In my /etc/sudoers.d/werner I'm using env_keep+="LS_COLORS LS_OPTIONS DISPLAY" then in /root/.bashrc the lines if test -n "$SUDO_USER" ; then SUDO_HOME=$(eval echo ~$SUDO_USER) if test -n "$SUDO_HOME" -a -s "$SUDO_HOME/.bashrc.root"; then export BASH_ENV="$SUDO_HOME/.bashrc.root" . "$SUDO_HOME/.bashrc.root" fi fi and in my $HOME/.bashrc.root if test "${DISPLAY%[0-9]*}" = : ; then for auth in /var/lib/xdm/authdir/authfiles/A${DISPLAY}-* /run/sddm/\{* ; do test -e "$auth" || continue XAUTHORITY=$auth break done if test -e "$XAUTHORITY" ; then export XAUTHORITY else unset XAUTHORITY fi fi ... and if gdm is used this may adopted to the locations where gdm stores its authority files