通过ssh -X作为特定用户登录时,在哪里更改.Xauthority文件的默认位置

时间:2014-03-04 10:01:26

标签: x11 xauth sshd

我需要将一组用户的.Xauthority文件位置更改为$HOME/tmp/.Xauthority,而不是默认$HOME/.Xauthority

我已经尝试过从以下几个方面赶上来的东西:

我使用以下内容在多个/etc/.profile.profile.bashrc ....等设置了这样的环境变量:XAUTHORITY=$HOME/tmp/.Xauthority

结果:

对sshx组(ssh -X server)用户进行的任何登录尝试都会导致锁定$HOME/.Xauthority超时。这就像没有改变任何东西。有趣的是,如果我echo $XAUTHORITY显示$HOME/tmp/.Xauthorityauthx正在运行,但在登录时却没有。

因此,我需要的处理必须在ssh -X之前或建立X连接时发生。我在哪里必须更改它,以便我只能解决一组用户,因为我不希望root或没有sshX组的用户受到影响,因为他们最终没有该目录?

2 个答案:

答案 0 :(得分:3)

我这样做的方法是在XAUTHORITY=/tmp/Xauthority-username中设置~/.ssh/environment,但这需要将/etc/ssh/sshd_config更改为PermitUserEnvironment yes

我使用/tmp因为它使每台机器保持本地。使用NFS上的主目录,这会成为瓶颈并导致竞争条件,即在多个远程主机上同时启动多个应用程序可能会导致某些应用程序失败。

答案 1 :(得分:2)

我提出了部分内容,但我现在仍然将.Xauthority重新定位到〜/ tmp / .Xauthority,这实际上是一个很好的进展。 (Ubuntu Server是目标操作系统)

所有设置保持相同只需要创建的文件〜/ .ssh / rc在连接ssh -X servername时加载:

if read proto cookie && [ -n "$DISPLAY" ]; then
            if [ `echo $DISPLAY | cut -c1-10` = 'localhost:' ]; then
                    # X11UseLocalhost=yes
                    echo add unix:`echo $DISPLAY |
                        cut -c11-` $proto $cookie
            else
                    # X11UseLocalhost=no
                    echo add $DISPLAY $proto $cookie
            fi | xauth -q -f ~/tmp/.Xauthority -
    fi

启动xauth并在您想要的位置创建文件,它还在.Xauthority文件中添加/创建条目以进行正确的身份验证。

现在你需要修改〜。/ profile,因为shell加载后需要知道它在哪里 找到.Xauthority文件。因此,我们在最顶部添加一行:

export XAUTHORITY=~/tmp/.Xauthority

这使我能够通过ssh -X servername连接到shell并启动任何X应用程序。让我们通过启动xeyes或xclock来尝试这个。

很酷,但还有另一个问题让我把它做对了,但我现在还没有解决方法。如果您尝试直接从遥控器启动X应用程序,例如:

x@y:~$ ssh -X servername xeyes

X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
X11 connection rejected because of wrong authentication.
Error: Can't open display: localhost:11.0

这是一个有趣的错误,因为如果你谷歌它有很多答案,但现在情况本身导致这样的假设,即当加载bash并且它被遗漏时某些东西是不同的。我唯一假设的是.profile中设置XAUTHORITY变量的行,但是如何在不加载shell的情况下设置它。如果我的用户在默认位置(〜/ .Xauthority)中有.Xauthority文件,为什么会这样?