Skip to content

Instantly share code, notes, and snippets.

@synackme
Last active August 29, 2015 13:57
Show Gist options
  • Save synackme/9885702 to your computer and use it in GitHub Desktop.
Save synackme/9885702 to your computer and use it in GitHub Desktop.
X11 forwarding after SUDO SU
# in your login directory on the target machine, add this to your .bashrc:
LIVE=`echo $DISPLAY | awk -F: '{print $2}' | awk -F. '{print $1}'` xauth list | grep unix:$LIVE | awk '{print "xauth add " $0}' >xuser
# su and add this to /root/.bashrc
XUSER=`who -m | awk '{print $1}'`
XUSERHOME=`grep ^$XUSER: /etc/passwd | awk -F: '{print $6}'`
if [ -s "$XUSERHOME/xuser" ]; then
. $XUSERHOME/xuser
echo Added xauth tokens for display for $XUSER
else
echo Original user $XUSER left no indication of X job
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment