I had trouble the other day running the Oracle installer in GUI mode over SSH. I had the -X option set, and I could run a GUI program as myself. The problem was that I couldn’t run the GUI program after I used sudo to change to my oracle user.
I found the answer on the “Bag of Tricks” blog:
To build upon that, I turned it into a script. The script adds the x cookie, runs an interactive bash, and finally removes the cookie at the end.
#!/bin/sh user=$1 if [ -z "$user" ]; then user=<default user> fi displayNum=`echo $DISPLAY | sed -e 's/^.*://' -e 's/\.*//'` echo "Display # = $displayNum" cookie=`xauth list | grep ":$displayNum"` echo "Cookie = $cookie" cookiename=`echo $cookie | sed 's/\s*MIT-MAGIC.*$//'` echo "Cookie Name: $cookiename" echo "user = $user" sudo -u $user bash -c "xauth list; xauth add $cookie; bash; xauth remove $cookiename"
I put the script in my ~/bin directory and called it ms (my-sudo). That way I could call it easily.
I hope someone finds that usedful. Any comments are welcomed.