The easiest way is to use ssh -X
to run commands as the other user. But this makes the applications run markedly slower, even locally.
The -i
option tells sudo
to reinitialize the environment. X applications require $DISPLAY
and (on some setups) $XAUTHORITY
, and may use other environment variable such as locale settings. Try without -i
, or if you must use -i
, run
sudo -i -u other_user \
env DISPLAY="$DISPLAY" XAUTHORITY="${XAUTHORITY-$HOME/.Xauthority}" \
xapplication
Even if you get rid of -i
, you might have to supply XAUTHORITY
explicitly: by default (if the variable is not set) it's .Xauthority
in the home directory.
So far I've been assuming the other user could read your $XAUTHORITY
. But that won't be the case unless you make it so (e.g. with setfacl -m user:other_user:r $XAUTHORITY
).
Alternatively, rather than let the other user read your $XAUTHORITY
, you could copy the right cookie to another file that the user can read.
xauth extract -f - "$DISPLAY" |
sudo -u other_user xauth -f ~other_user/.Xauthority merge -
Note that allowing another user access to your display allows him to do almost anything with it, including sending fake keypresses to applications. So if you were changing users for isolation, you won't get much.
-i
? Have you tried removing that?