If you are a sudoer but do not know the root password, you may encounter the following similar information when running some X programs that require special permissions:
[Pc01]> sudo ethereal
Ssh (28492) X11 connection rejected because of wrong authentication.
The application 'ethereal' lost its connection to the display localhost: 11.0;
Most likely the X server was shut down or you killed/destroyed
The application.
[Pc01]> sudo su
[Pc01]> whoami
Root
[Pc01]> ethereal
Ssh (28492) X11 connection rejected because of wrong authentication.
The application 'ethereal' lost its connection to the display localhost: 11.0;
Most likely the X server was shut down or you killed/destroyed
The application.
This issue is especially prominent when you need to log on to a remote machine (of course, ssh must support X11 forward ).
The cause of this error is that the X11 authentication mechanism is completed through cookies, and these cookies are only applied to one user by default. Therefore, after su or sudo is used to change the euid, the original X11 authentication information is invalid and thus the program cannot be run.
To avoid this problem, you can use the following methods.
[Pc01]> echo $ DISPLAY
Localhost: 10.0
[Pc01]> xauth list | grep: 10
Pc01.xx./unix: 10 MIT-MAGIC-COOKIE-1 limit 66d9259e65500229ff48344df0371
[Pc01]> sudo su-
[Root @ pc01 ~] # Xauth add pc01.xx./unix: 10 MIT-MAGIC-COOKIE-1 limit 66d9259e65500229ff48344df0371
[Root @ pc01 ~] # Ethereal
This method transfers the original X11 verification information to new users and establishes a new connection with Xserver. This solves the problem of X11 verification information loss during the su process.
To simplify this process, you can write a script to automatically implement this function, which may be called xsudo:
#! /Bin/bash
#
# Xsudo...
#
Usage ()
...{
Echo "xsudo to forward X11 authentication when sudo, almost the same
Sudo"
}
If [$ #-lt 1]; then
Usage
Exit 0
Fi
Host = $ HOST
Display = $ DISPLAY
Port = 'echo $ DISPLAY | cut-d:-f 2 | cut-d.-f 1'
Key = 'xauth list | grep $ host | grep ": $ port" | grep unix'
Sudo su-c "xauth add $ key & $ *"
After adding xsudo to path, you can easily add sudo: D