SSH X11转发不起作用。 为什么?

这是一个debugging问题。 当你要求澄清,请确保它不是已经在下面覆盖。

我有4台机器:Z,A,N和M.

要到达A,您必须首先login到Z.

要到达M,您必须先login到N。

以下工作:

ssh -XZ xclock ssh -XZ ssh -XZ xclock ssh -XZ ssh -XA xclock ssh -XN xclock ssh -XN ssh -XN xclock 

但是这不是:

 ssh -XN ssh -XM xclock Error: Can't open display: 

loginM时显然没有设置$ DISPLAY。问题是为什么?

Z和A共享相同的NFS-homedir。 N和M共享相同的NFS-homedir。 N的sshd运行在一个非标准的端口上。

 $ grep X11 <(ssh Z cat /etc/ssh/ssh_config) ForwardX11 yes # ForwardX11Trusted yes $ grep X11 <(ssh N cat /etc/ssh/ssh_config) ForwardX11 yes # ForwardX11Trusted yes 

N:/etc/ssh/ssh_config == Z:/etc/ssh/ssh_configM:/etc/ssh/ssh_config == A:/etc/ssh/ssh_config

/etc/ssh/sshd_config对于所有4台机器都是相同的(除了某些组的端口和login权限外)。

如果我将M的ssh端口转发到本地机器,它仍然不起作用:

 terminal1$ ssh -L 8888:M:22 N terminal2$ ssh -X -p 8888 localhost xclock Error: Can't open display: 

A:.Xauthority包含A,但是M:.Xauthority不包含M.

xauth安装在A和M的/usr/bin/xauth

login到A时正在运行xauth ,但login到M时运行。

ssh -vvv到A和M时, ssh -vvv不会抱怨X11或xauth。两者都会说:

 debug2: x11_get_proto: /usr/bin/xauth list :0 2>/dev/null debug1: Requesting X11 forwarding with authentication spoofing. debug2: channel 0: request x11-req confirm 0 debug2: client_session2_setup: id 0 debug2: channel 0: request pty-req confirm 1 debug1: Sending environment. 

我有一种感觉,这个问题可能与M缺lessM:.Xauthority(由于未被运行的xauth引起)或者$ DISPLAY被某个login脚本禁用了,但我无法弄清楚什么是错的。

– 更新20110628

我不知道sshrc所以这是一个很好的猜测。 但是,唉,这里不是问题。 它在四台机器中都不存在:

 $ ls ~/.ssh/rc /etc/ssh/sshrc ls: cannot access /home/tange/.ssh/rc: No such file or directory ls: cannot access /etc/ssh/sshrc: No such file or directory 

如上所述,$ DISPLAYvariables没有在M上设置,但在A:

 $ ssh -XN ssh -XM 'echo \$DISPLAY' <<empty>> $ ssh -XZ ssh -XA 'echo \$DISPLAY' localhost:14.0 

工作会话和非工作会话输出的差异(注意:非工作会话中没有关于X转发或xauth的警告):

 $ stdout ssh -XZ ssh -vX A 'echo \$DISPLAY' >/tmp/a $ stdout ssh -XN ssh -vX M 'echo \$DISPLAY' >/tmp/b $ diff /tmp/a /tmp/b 4c4 < debug1: Connecting to A [1.1.1.5] port 22. --- > debug1: Connecting to M [1.1.3.3] port 22. 23,24c23,24 < debug1: Host 'A' is known and matches the RSA host key. < debug1: Found key in /home/tange/.ssh/known_hosts:35 --- > debug1: Host 'M' is known and matches the RSA host key. > debug1: Found key in /home/tange/.ssh/known_hosts:1 43d42 < debug1: Sending env LC_ALL = en_US.UTF-8 46c45 < localhost:14.0 --- > 53,54c52,53 < Transferred: sent 2384, received 2312 bytes, in 0.2 seconds < Bytes per second: sent 10714.8, received 10391.2 --- > Transferred: sent 2336, received 2296 bytes, in 0.0 seconds > Bytes per second: sent 54629.1, received 53693.7 

在M上安装lsh-server而不是openssh-server可以修复X-forwarding,但这是一个不可接受的解决scheme。

你不需要指定M上的/etc/ssh/sshd_config X11Forwarding是否设置为yes ,这肯定会解释为什么它不起作用。

在我的情况下,它是防火墙的默认策略,设置为“DROP”。

您需要检查哪个端口正在被监听(通常是$ DISPLAY环境variables中的6000 +值)并设置适当的规则。 以root身份运行:

 # echo $DISPLAY localhost:10.0 # netstat -altnp | grep LIST tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 13670/sshd # iptables -A INPUT -i lo -p tcp -m tcp --dport 6010 -j ACCEPT # iptables -A INPUT -i lo -p tcp -m tcp --sport 6010 -j ACCEPT # iptables -A OUTPUT -o lo -p tcp -m tcp --dport 6010 -j ACCEPT # iptables -A OUTPUT -o lo -p tcp -m tcp --sport 6010 -j ACCEPT