Linux 设置 X11 通过 ssh 转发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19589844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
set-up X11 Forwarding over ssh
提问by SuperUser320
I'm attempting to set up x11 forwarding to monitor video on an embedded robotics platform yet I cannot seem to get the board to generate graphical output. I'm running Arch Linux on a Beagleboard xM wired directly over ethernet (though, I plan to use WiFi in the future). When I try to set the DISPLAY variable it will accept it but when I attempt to run an x11 application is says:
我正在尝试设置 x11 转发以在嵌入式机器人平台上监控视频,但我似乎无法让电路板生成图形输出。我在直接通过以太网连接的 Beagleboard xM 上运行 Arch Linux(不过,我计划在未来使用 WiFi)。当我尝试设置 DISPLAY 变量时,它会接受它,但是当我尝试运行 x11 应用程序时说:
(Object:287): Gtk-WARNING **: cannot open display: [displaynamehere]
obviously [displaynamehere] was whatever I tried to set as the display, yet no display location seemed to work. What's weird is that whenever I connect through ssh -X it does not give me any errors and it does not save my DISPLAY variable.
显然 [displaynamehere] 是我试图设置为显示的任何内容,但似乎没有显示位置有效。奇怪的是,每当我通过 ssh -X 连接时,它都不会给我任何错误,也不会保存我的 DISPLAY 变量。
(EDIT) I also checked the debug log and got this output:
(编辑)我还检查了调试日志并得到了这个输出:
debug2: load_server_config: filename /etc/ssh/sshd_config
debug2: load_server_config: done config len = 315
debug2: parse_server_config: config /etc/ssh/sshd_config len 315
debug3: /etc/ssh/sshd_config:53 setting AuthorizedKeysFile .ssh/authorized_keys
debug3: /etc/ssh/sshd_config:75 setting ChallengeResponseAuthentication no
debug3: /etc/ssh/sshd_config:96 setting UsePAM yes
debug3: /etc/ssh/sshd_config:101 setting X11Forwarding yes
debug3: /etc/ssh/sshd_config:104 setting PrintMotd no
debug3: /etc/ssh/sshd_config:108 setting UsePrivilegeSeparation sandbox
debug3: /etc/ssh/sshd_config:124 setting Subsystem sftp /usr/lib/ssh/sftp-server
debug1: sshd version OpenSSH_6.3, OpenSSL 1.0.1e 11 Feb 2013
debug3: Incorrect RSA1 identifier
debug1: read PEM private key done: type RSA
debug3: Incorrect RSA1 identifier
debug3: Could not load "/etc/ssh/ssh_host_rsa_key" as a RSA1 public key
debug1: private host key: #0 type 1 RSA
debug3: Incorrect RSA1 identifier
debug1: read PEM private key done: type DSA
debug3: Incorrect RSA1 identifier
debug3: Could not load "/etc/ssh/ssh_host_dsa_key" as a RSA1 public key
debug1: private host key: #1 type 2 DSA
debug3: Incorrect RSA1 identifier
debug1: read PEM private key done: type ECDSA
debug3: Incorrect RSA1 identifier
debug3: Could not load "/etc/ssh/ssh_host_ecdsa_key" as a RSA1 public key
debug1: private host key: #2 type 3 ECDSA
debug1: rexec_argv[0]='/usr/bin/sshd'
debug1: rexec_argv[1]='-ddd'
debug3: oom_adjust_setup
Set /proc/self/oom_score_adj from 0 to -1000
debug2: fd 3 setting O_NONBLOCK
debug1: Bind to port 22 on 0.0.0.0.
Bind to port 22 on 0.0.0.0 failed: Address already in use.
debug2: fd 3 setting O_NONBLOCK
debug3: sock_set_v6only: set socket 3 IPV6_V6ONLY
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
Any suggestions would be greatly appreciated, I've been trying at this with google for almost a week now to no avail.
任何建议将不胜感激,我已经用谷歌尝试了近一个星期,但无济于事。
Thanks a lot!
非常感谢!
回答by phil_w
ssh should set the DISPLAY automatically. usual suspects: missing "X11Forwarding yes" in /etc/ssh/sshd_config
ssh 应该自动设置 DISPLAY。通常的嫌疑人:在 /etc/ssh/sshd_config 中缺少“X11Forwarding yes”
To debug you can run verbose mode on the client and server and you may notice something : try on the "server" side (debug mode, no daemon)
要调试,您可以在客户端和服务器上运行详细模式,您可能会注意到一些事情:尝试在“服务器”端(调试模式,没有守护进程)
$ /usr/sbin/sshd -d -p 222
on the "client":
在“客户端”上:
$ ssh -v -Y [email protected] -p 222
Once in a while I meet an odd thing, like 'missing xauth' ...
偶尔我会遇到一个奇怪的事情,比如“缺少 xauth”……
回答by Yordan Georgiev
On the server
在服务器上
Edit /etc/ssh/sshd_config
:
编辑/etc/ssh/sshd_config
:
AllowAgentForwarding yes
AllowTcpForwarding yes
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
Restart the sshd daemon:
重新启动 sshd 守护进程:
sudo service sshd restart
# or
sudo /etc/init.d/ssh restart
# or whatever way of restarting your box services works on your distro...
yum -y update xauth
apt-get -y update xauth
yum -y install xauth
apt-get -y install xauth
Now exit the server:
现在退出服务器:
exit
On the client
在客户端
Set the DISPLAY
environment variable locally:
在DISPLAY
本地设置环境变量:
export DISPLAY=:0.0
and start a trusted SSH connection to the server:
并启动到服务器的可信 SSH 连接:
ssh -Y $ssh_user@$ssh_server
Verify success with a graphical app. Install an app supporting X11 forwarding, if needed. As an example:
使用图形应用程序验证成功。如果需要,安装支持 X11 转发的应用程序。举个例子:
yum -y install xclock
and action:
和行动:
for i in {1..3} ; do bash -c "xclock &" ; done ;
回答by Baris Demiray
Whenever I had this problem it was almost always about following two options, I think you should set them as below before making any further changes on your configuration like setting DISPLAY, etc.
每当我遇到这个问题时,几乎总是关于以下两个选项,我认为您应该在对配置进行任何进一步更改(例如设置 DISPLAY 等)之前将它们设置如下。
X11Forwarding yes
X11UseLocalhost no