x11 应用程序在 su 后无法工作

x11 应用程序在 su 后无法工作

su在终端(本地终端或带有 X11 转发的 ssh)上,用户可以打开 X 应用程序,但是其他用户在ing后无法打开。

请参阅下面的输出。

u1@cluster:~$ xclock
u1@cluster:~$ su
Password:
root@cluster:# su - u2
[u2@cluster ~]$ xclock
No protocol specified
Error: Can't open display: localhost:11.0
[u2@cluster ~]$

那么,解决办法是什么呢?

答案1

/usr/local/bin我通常在或中创建以下脚本$HOME/bin

#!/bin/bash
HOSTNAME=`uname -n`
ARG=`echo $DISPLAY | sed -e "s/localhost/$HOSTNAME\/unix/"`
XAUTH=`/usr/bin/xauth -i -f ~/.Xauthority list ${ARG}`

echo "The following is used for graphical displays through ssh."
echo "Copy and paste the following commands AFTER you have \"su - [user]\""
echo "----------------  Copy below  ------------------------------------"
echo "DISPLAY=$DISPLAY;export DISPLAY"
echo "/usr/bin/xauth -bi add \\"
echo "${XAUTH}"
echo "----------------  Copy above  ------------------------------------"

你将执行这个脚本使用susudo.成为其他用户后,按照说明剪切并粘贴输出。你的X程序应该运行。

[bschuck@dhcp-10-100-11-138 ~]$ bin/xtunnel 
The following is used for graphical displays through ssh.
Copy and paste the following commands AFTER you have "su - [user]"
----------------  Copy below  ------------------------------------
DISPLAY=localhost:10.0;export DISPLAY
/usr/bin/xauth -bi add \
dhcp-10-100-11-138/unix:10  MIT-MAGIC-COOKIE-1 \
b64ace6b49bb1b49c59679a2db6411eb
----------------  Copy above  ------------------------------------
[bschuck@dhcp-10-100-11-138 ~]$ su - zippy
Password: 
[zippy@dhcp-10-100-11-138 ~]$ DISPLAY=localhost:10.0;export DISPLAY
[zippy@dhcp-10-100-11-138 ~]$ /usr/bin/xauth -bi add \
> dhcp-10-100-11-138/unix:10  MIT-MAGIC-COOKIE-1  
b64ace6b49bb1b49c59679a2db6411eb
[zippy@dhcp-10-100-11-138 ~]$ xclock &
[1] 6076
[zippy@dhcp-10-100-11-138 ~]$

相关内容