Thursday, December 20, 2012

Cannot connect to DISPLAY after su


[i copy it from http://jianmingli.com/wp/?p=724]

Cause:

X win cookie not carried over after sudo login as another user.

Solutions One:

1. Login as first user (user1).
2. Run 'echo $DISPLAY'
 
bash-3.00$ echo $DISPLAY
localhost:10.0
 
2. Run 'xauth list'
xauth list
box.my.com/unix:10  MIT-MAGIC-COOKIE-1  4f76c629f8cdbf26ce4ae646cc24448c
box.my.com/unix:11  MIT-MAGIC-COOKIE-1  1acd10ab0fd098a86aba7aa691d7c067
box.my.com/unix:12  MIT-MAGIC-COOKIE-1  e007ee6844c417a6b866d66c7bbcbc7d
For Solaris 10, xauth is in the /usr/openwin/bin directory.
3. sudo to second user (user2) with command like
sudo su - user2
4. Set $DISPLAY env to the same as user1's.
 
DISPLAY=localhost:10.0; export DISPLAY
 
5. Run "xauth add" and append the entry from user1's "xauth list" that matches the display number. For example, user1 $DISPLAY is localhost:10.0, so we'll append box.my.com/unix:10entry.
xauth add box.my.com/unix:10  MIT-MAGIC-COOKIE-1  4f76c629f8cdbf26ce4ae646cc24448c
6. Test with xclock:
 
xclock

No comments:

Post a Comment