SSH X11转发无法工作。

15

我一直在尝试从我的笔记本电脑实现X11端口转发。我无法弄清楚为什么它无法工作。

当我尝试运行xterm时,我会收到此消息:

X11 connection rejected because of wrong authentication.
xterm Xt error: Can't open display: localhost:10.0

我不知道这是否相关,但当我登录时,我会收到以下消息:

/usr/bin/xauth:  timeout in locking authority file /home/sphillips/.Xauthority

我一直在想,问题可能是我的笔记本电脑上的本地用户是skp,而这台服务器上的用户名是sphillips。我已经能够让使用相同skp登录的其他计算机实现X11转发。
此外,使用Xming和Putty从Windows计算机到同一服务器进行X11端口转发也可以正常工作。我必须手动配置DISPLAY变量为IP地址和显示0.0,但它可以工作。
我在我的机器上运行了xhost +,试图绕过任何安全问题。但仍然没有成功。
在服务器上,我检查了配置:
$ sudo grep X11Forwarding /etc/ssh/sshd_config
#X11Forwarding no
X11Forwarding yes
#   X11Forwarding no

我的电脑上也出现了这个问题:

$ sudo grep X11Forwarding /etc/ssh/sshd_config
[sudo] password for skp: 
#X11Forwarding no
X11Forwarding yes
#   X11Forwarding no

我的服务器是RedHat Enterprise Linux 6,我的笔记本电脑是Fedora 15。

有人可以给我一些想法,尝试从我的笔记本电脑使SSH X11转发工作吗?


我因此获得了飘草徽章!这是好事还是坏事?我只希望有人能提出其他我可以尝试的想法。 - digitaleagle
5个回答

13

我终于找到了答案(至少对于我的情况是这样)!问题出在SELinux上。我关闭了SELinux,就没有问题了。

如果您对所有细节感兴趣,可以在我的博客上阅读,但请允许我在此详细说明相关事实...

在远程机器上,我使用了dmesg来查看日志消息:

dmesg | tail

我发现了许多类似这样的消息:

type=1400 audit(1332520527.110:51337): avc: denied { read } for pid=25240 comm="sshd" name="authorized_keys" dev=dm-5 ino=167 scontext=unconfined_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:home_root_t:s0 tclass=file
您可以使用以下命令检查SELinux的状态:

$ sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: permissive
Policy version: 24
Policy from config file: targeted

你可以使用以下命令将其切换到宽容模式:

setenforce 0

如果想了解更多有关SELinux的信息,我发现Red Hat指南非常有帮助。此外,对于其他SSH问题,我发现David的博客有助于获取日志。

对我而言,在此之后,我的X11转发开始无故障地运行。

SELinux阻止了其他几个不同的东西。它无法创建必要的文件以使密钥认证正常工作。我还发现它阻止ssh-keygen在主目录中创建密钥。


3

我也遇到过这个问题。但是在我的情况下,是因为几天前我移除了IPv6支持。后来我看到了这个帖子,解释了如何确保sshd只使用IPv4。

以下是我的做法,添加以下内容:

AddressFamily inet

将以下内容添加到您的ssh_config文件中(在Ubuntu上为/etc/ssh/sshd_config),并使sshd重新加载其配置(kill -SIGHUP pid-of-sshd)。


此外,Google Compute Engine的最新Ubuntu启动磁盘映像在尝试使用Putty进行ssh时需要这行命令!我花了一个工作日来解决这个问题。 http://www.straightrunning.com/XmingNotes/trouble.php - re Paul
您可以使用 ssh 命令行参数 -o "AddressFamily inet" 进行测试。 - danodonovan

2

我在Debian OpenVZ容器上遇到了同样的问题,问题似乎来自于我的/etc/hosts文件,其中“localhost”被分配给了LAN IP,而不是127.0.0.1。

之前:

192.168.0.15  dagi dagi.domain.net localhost localhost.localdomain

之后:

192.168.0.15  dagi dagi.domain.net
127.0.0.1     localhost localhost.localdomain

之后,ssh -Xssh -Y 都可以正常使用,甚至无需重启sshd。


谢谢Chi,这是一个好建议。我确实遇到了这个问题。我的笔记本电脑上的/etc/hosts将主机指向127.0.0.1。但是,我已经更改了它,但仍然没有任何不同。我实际上尝试了所有3个IP地址。我尝试了有线IP、无线IP和VPN(tun0-00)。我仍然得到相同的结果。 - digitaleagle
谢谢 Chi,这节省了我很多时间。 - jhilmer

1

除了@Chl上面的答案,我也遇到了一个损坏的~/.Xauthority文件。

由于某种原因,即使在我的主目录下,它也是由root所有。所以我必须使用sudo -s,然后删除它。

然后用touch ~/.Xauthority重新创建它。

之后,在Ubuntu 14.04下对于我来说X转发起作用了。


同样地,我只是没有一个 ~/.Xauthority 文件,创建它(空的)解决了问题。 - Soren Bjornstad

0
sudo grep X11Forwarding /etc/ssh/sshd_config

X11Forwarding yes 
#sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: permissive
Policy version: 24
Policy from config file: targeted
#You can turn it to permissive mode with this command:
#setenforce 0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接