Last active
December 17, 2015 11:19
-
-
Save uarun/5601087 to your computer and use it in GitHub Desktop.
Script to carry X11 Forwarding even after Sudo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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