Forward X11 over SSH after you su
February 3rd, 2010
Enabling SSH forwarding for X11 in general is easy: you simply put X11Forwarding yes in /etc/ssh/sshd_config, then SSH into the server with the -X or -Y (as appropriate for you).
However, if you want to be able to SSH in as a non-privileged user and su to become root, you’ll need to do a little more. Adding the following to the non-privileged user’s .bashrc works for me:
# Allows su to use X11
if [ ! -n "$XAUTHORITY" ]; then
export XAUTHORITY=~/.Xauthority
fi
su passes environment variables to the new shell, so this ensures that applications that use the X server know where to look for the SSH forwarding info.
This manual configuration isn’t an issue with all distributions, but was required for my Debian Lenny box.



And it works if you use sudo to become root as well!
TYVM, Aiden