如果你是一个sudoer,却不知道root的密码,那么你在运行某些需要特别权限的X程序的时候可能会遇到以下的类似信息:
[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.
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.
该问题在需要登录到远程机器上时尤其突出(当然,ssh需要支持X11 forward)。
出现该错误的原因是:X11验证机制是通过COOKIE来完成的,而这些COOKIE在默认情况下只应用于一个用户。因此在使用su或者sudo改变euid以后,原有的X11验证信息已经无效,从而无法运行程序。
为了避免这个问题,可以采取以下方法。








此法将原有的X11验证信息传递给新的用户,重新建立了和Xserver的连接,从而解决了X11验证信息在su过程中丢失的问题。
为了简化此过程,可以写一个脚本自动实现此功能,不妨称其为xsudo:























将xsudo添加到path,就可以很方便地随意sudo了:D