如何修复su时丢失的X11验证信息(xsudo bash版)
来源:互联网 发布:计算器编程学习 编辑:程序博客网 时间:2024/06/05 00:58
如果你是一个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验证信息已经无效,从而无法运行程序。
为了避免这个问题,可以采取以下方法。
[pc01] > echo $DISPLAY
localhost:10.0
[pc01] > xauth list |grep :10
pc01.xx./unix:10 MIT-MAGIC-COOKIE-1 10866d9259e65500229ff48344df0371
[pc01] > sudo su -
[root@pc01 ~]# xauth add pc01.xx./unix:10 MIT-MAGIC-COOKIE-1 10866d9259e65500229ff48344df0371
[root@pc01 ~]# ethereal
localhost:10.0
[pc01] > xauth list |grep :10
pc01.xx./unix:10 MIT-MAGIC-COOKIE-1 10866d9259e65500229ff48344df0371
[pc01] > sudo su -
[root@pc01 ~]# xauth add pc01.xx./unix:10 MIT-MAGIC-COOKIE-1 10866d9259e65500229ff48344df0371
[root@pc01 ~]# ethereal
此法将原有的X11验证信息传递给新的用户,重新建立了和Xserver的连接,从而解决了X11验证信息在su过程中丢失的问题。
为了简化此过程,可以写一个脚本自动实现此功能,不妨称其为xsudo:
#!/bin/bash
#
# xsudo ...
#
Usage()
...{
echo "xsudo to forward X11 authentication when sudo, almost the same as
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 && $*"
#
# xsudo ...
#
Usage()
...{
echo "xsudo to forward X11 authentication when sudo, almost the same as
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 && $*"
将xsudo添加到path,就可以很方便地随意sudo了:D
- 如何修复su时丢失的X11验证信息(xsudo bash版)
- su - postgres时,显示为bash-4.2$如何解决
- su - postgres时,显示为bash-4.2$如何解决
- 修复丢失的pv
- 修复开机出现CMOS信息丢失故障
- su: /bin/bash: 权限不够 的解决方法
- grub丢失的修复方法
- linux修复丢失的分区表
- 如何防止丢失任何 bash 历史命令?
- 硬盘数据丢失,到底该如何修复?
- 如何设置readonly的Textbox回传后信息不丢失!
- 信息的丢失
- msiexec.exe进程介绍及如何修复被丢失的msiexec.exe系统文件
- 修复VS2005丢失的系统模板
- mysql服务丢失后的修复
- Fragment输入状态丢失的修复:
- Mts视频丢失损坏的恢复修复
- 查看修复HDFS中丢失的块
- svn常用命令
- Struts_LookupDispatchAction简单的例子
- webwork学习笔记四
- javascript数组使用
- Linux软件安装之RPM的安装技巧
- 如何修复su时丢失的X11验证信息(xsudo bash版)
- 揭示win32 api拦截细节
- RPM应用之安装篇
- 一道面试题目7 删除重复纪录
- 常用数据库JDBC连接写法
- DataGridView控件用法合集(十一)
- 关于使用XFire...
- Struts_DispatchAction简单的例子
- C#高级编程学习笔记--------构造函数(1)