document updated 12 years ago, on Feb 9, 2012
This is an alternative to using sux / sudox to allow you to use X apps after sudoing.
It's hands-off, it lets you use your normal su/sudo commands without any alteration.
Change /etc/sudoers
Run visudo and add this:
Defaults env_keep += "DISPLAY XAUTHORITY"
Change ~/.bashrc
In the normal user account (before you su to root), change your .bashrc to include this:
# avoid having to use sux/sudox when changing to root (this line cooperates with /etc/sudoers env_keep)
[ -n "$DISPLAY" -a -e "$HOME/.Xauthority" ] && export XAUTHORITY="$HOME/.Xauthority"
You'll have to logout and back in, before this will take effect.
Change ~/.ssh/config
This is somewhat tangential, but it's another way to make things convenient.
On your main X machine, add this to the bottom of your ~/.ssh/config: