X11 connection rejected because of wrong authentication

Опубликовано jeord -

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'

  1.  
  2. bash-3.00$ echo $DISPLAY
  3. localhost:10.0
  4.  

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

  1. sudo su - user2

4. Set $DISPLAY env to the same as user1's.

  1.  
  2. DISPLAY=localhost:10.0; export DISPLAY
  3.  

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:10 entry.

xauth add box.my.com/unix:10  MIT-MAGIC-COOKIE-1  4f76c629f8cdbf26ce4ae646cc24448c

6. Test with xclock:

  1.  
  2. xclock
  3.  

Automate Solution One

Solution one can be automated by two scripts, one on user1 side and another user2.
1. Create a shell script, named sudouser2, on user1 side.

  1.  
  2. #!/usr/bin/bash
  3.  
  4. # Remember DISPLAY
  5. echo $DISPLAY > /tmp/.echoUser1DISPLAY.txt
  6. chmod a+r /tmp/.echoUser1DISPLAY.txt
  7.  
  8. # Remember cookie
  9. xauth list|grep `echo $DISPLAY |cut -c10-12` > /tmp/.parseUser1Xauth.txt
  10. chmod a+r /tmp/.parseUser1Xauth.txt
  11.  
  12. sudo su - user2
  13.  

2. Give sudouser2 execute permission.

  1.  
  2. chmod u+x dusouser2
  3.  

3. Run ./sudouser2 to sudo into user2

  1.  
  2. ./sudouser2
  3.  

4. Create a shell script, name setxwin , on user2 side.

  1.  
  2. xauth add `cat /tmp/.parseUser1Xauth.txt`
  3. export DISPLAY=`cat /tmp/.echoUser1DISPLAY.txt`
  4.  

5. Run . ./setxwin on user2 shell. Optionally, included setxwin in shell start script such as .profile file.

  1.  
  2. . ./setxwin
  3.  

6. Test with xclock:

  1.  
  2. xclock
  3.  

Solution Two:

Add to /etc/sudoers file

Defaults env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"


Thanks Jianming Li for
http://jianmingli.com/wp/?p=724

Теги