Skip to content

Instantly share code, notes, and snippets.

@uarun
Last active December 17, 2015 11:19
Show Gist options
  • Select an option

  • Save uarun/5601087 to your computer and use it in GitHub Desktop.

Select an option

Save uarun/5601087 to your computer and use it in GitHub Desktop.
Script to carry X11 Forwarding even after Sudo
#!/bin/sh
user=$1
if [ -z "$user" ]; then
user=liquidnt
fi
displayNum=`echo $DISPLAY | sed -e 's/^.*://' -e 's/\.[0123456789]*//'`
echo "Display # = $displayNum"
cookie=`xauth list | grep ":$displayNum"`
echo "Cookie = $cookie"
cookiename=`echo $cookie | sed 's/\s*MIT-MAGIC.*$//'`
echo "Cookie Name: $cookiename"
echo -e "user = $user\n"
echo "Run the following commands: "
echo "=========================== "
echo " sudo su - $user"
echo " xauth list"
echo " xauth add $cookie"
echo
echo "Run the following to remove the cookie: "
echo "====================================== "
echo " xauth remove $cookiename"
## sudo -u $user bash -c "xauth list; xauth add $cookie; bash; xauth remove $cookiename"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment