Mr.*_*nce 461 ssh xorg xforwarding
我有一台运行 Ubuntu 的机器,我从 Fedora 14 机器通过 SSH 连接到它。我想将 X 从 Ubuntu 机器转发回 Fedora,以便我可以远程运行图形程序。两台机器都在局域网上。
我知道该-X选项在 SSH 中启用 X11 转发,但我觉得我错过了一些步骤。
通过 SSH 将 X 从 Ubuntu 机器转发到 Fedora 需要哪些步骤?
Gil*_*il' 543
客户端和服务端都需要开启X11转发。
在客户端,-X(大写 X)选项ssh启用 X11 转发,您可以使用ForwardX11 yesin将其设为默认值(对于所有连接或特定连接)~/.ssh/config。
在服务器端,X11Forwarding yes必须在/etc/ssh/sshd_config. 请注意,默认设置是不转发(某些发行版在默认设置中将其打开/etc/ssh/sshd_config),并且用户无法覆盖此设置。
该xauth程序必须安装在服务器端。如果那里有任何 X11 程序,那很可能xauth会在那里。在不太可能的情况下xauth安装在非标准位置,它可以被调用~/.ssh/rc(在服务器上!)。
请注意,您不需要在服务器上设置任何环境变量。DISPLAY并且XAUTHORITY将被自动设置到正确的值。如果您运行 ssh 并且DISPLAY未设置,则表示 ssh 没有转发 X11 连接。
以确认SSH是转发X11,检查用于容纳线Requesting X11 forwarding中的输出ssh -v -X。请注意,服务器不会以任何一种方式回复,这是隐藏潜在攻击者详细信息的安全预防措施。
小智 118
要通过 SSH 进行 X11 转发,您需要准备三件事:
如果您同时拥有#1 和#2,但缺少#3,那么您最终会得到一个空的DISPLAY环境变量。
汤到坚果,这里是如何让 X11 转发工作:
在您的服务器上,确保/etc/ssh/sshd_config包含:
X11Forwarding yes
X11DisplayOffset 10
Run Code Online (Sandbox Code Playgroud)
您可能需要 SIGHUPsshd以便它接收这些更改。
cat /var/run/sshd.pid | xargs kill -1
Run Code Online (Sandbox Code Playgroud)
在您的服务器上,确保您已xauth安装。
belden@skretting:~$ which xauth
/usr/bin/xauth
Run Code Online (Sandbox Code Playgroud)
如果你没有xauth安装,你会遇到这个empty DISPLAY environment variable问题。
在您的客户端上,连接到您的服务器。一定要告诉 ssh 允许 X11 转发。我更喜欢
belden@skretting:~$ ssh -X blyman@the-server
Run Code Online (Sandbox Code Playgroud)
但你可能喜欢
belden@skretting:~$ ssh -o ForwardX11=yes blyman@the-server
Run Code Online (Sandbox Code Playgroud)
或者你可以在你的~/.ssh/config.
DISPLAY今天早些时候,当 ssh 连接到我没有管理的新服务器时,我遇到了这个空的环境变量。追踪缺失的xauth部分有点有趣。这是我所做的,以及你也可以做的。
在我作为管理员的本地工作站上,我确认/etc/ssh/sshd_config已设置为转发 X11。当我ssh -X回到本地主机时,我确实得到了DISPLAY正确的设置。
强制DISPLAY取消设置并不太难。我只需要看什么sshd,ssh正在做什么来正确设置它。这是我一路上所做的一切的完整输出。
blyman@skretting:~$ mkdir ~/dummy-sshd
blyman@skretting:~$ cp -r /etc/ssh/* ~/dummy-sshd/
cp: cannot open `/etc/ssh/ssh_host_dsa_key' for reading: Permission denied
cp: cannot open `/etc/ssh/ssh_host_rsa_key' for reading: Permission denied
Run Code Online (Sandbox Code Playgroud)
我没有使用 sudo 强制将我的ssh_host_{dsa,rsa}_key文件复制到位,而是使用 ssh-keygen 为自己创建了虚拟文件。
blyman@skretting:~$ ssh-keygen -t rsa -f ~/dummy-sshd/ssh_host_rsa_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/blyman/dummy-sshd/ssh_host_rsa_key.
Your public key has been saved in /home/blyman/dummy-sshd/ssh_host_rsa_key.pub.
Run Code Online (Sandbox Code Playgroud)
冲洗并重复-t dsa:
blyman@skretting:~$ ssh-keygen -t dsa -f ~/dummy-sshd/ssh_host_dsa_key
# I bet you can visually copy-paste the above output down here
Run Code Online (Sandbox Code Playgroud)
编辑~/dummy-sshd/sshd_config以指向正确的新ssh_host密钥文件。
# before
blyman@skretting:~$ grep ssh_host /home/blyman/dummy-sshd/sshd_config
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
# after
blyman@skretting:~$ grep ssh_host /home/blyman/dummy-sshd/sshd_config
HostKey /home/blyman/dummy-sshd/ssh_host_rsa_key
HostKey /home/blyman/dummy-sshd/ssh_host_dsa_key
Run Code Online (Sandbox Code Playgroud)
火起来sshd的非分离模式中的新端口:
blyman@skretting:~$ sshd -p 50505 -f ~/dummy-sshd/sshd_config -d
sshd re-exec requires execution with an absolute path
Run Code Online (Sandbox Code Playgroud)
哎呀,最好更正这条路:
blyman@skretting:~$ /usr/sbin/sshd -p 50505 -f ~/dummy-sshd/sshd_config -d
debug1: sshd version OpenSSH_5.5p1 Debian-4ubuntu6
debug1: read PEM private key done: type RSA
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: Checking blacklist file /usr/share/ssh/blacklist.DSA-1024
debug1: Checking blacklist file /etc/ssh/blacklist.DSA-1024
debug1: private host key: #1 type 2 DSA
debug1: setgroups() failed: Operation not permitted
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-p'
debug1: rexec_argv[2]='50505'
debug1: rexec_argv[3]='-f'
debug1: rexec_argv[4]='/home/blyman/dummy-sshd/sshd_config'
debug1: rexec_argv[5]='-d'
Set /proc/self/oom_adj from 0 to -17
debug1: Bind to port 50505 on 0.0.0.0.
Server listening on 0.0.0.0 port 50505.
debug1: Bind to port 50505 on ::.
Server listening on :: port 50505.
Run Code Online (Sandbox Code Playgroud)
弹出一个新终端并通过 ssh 进入localhost端口50505:
blyman@skretting:~$ ssh -p 50505 localhost
The authenticity of host '[localhost]:50505 ([::1]:50505)' can't be established.
RSA key fingerprint is 81:36:a5:ff:a3:5a:45:a6:90:d3:cc:54:6b:52:d0:61.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:50505' (RSA) to the list of known hosts.
Linux skretting 2.6.35-32-generic #67-Ubuntu SMP Mon Mar 5 19:39:49 UTC 2012 x86_64 GNU/Linux
Ubuntu 10.10
Welcome to Ubuntu!
* Documentation: https://help.ubuntu.com/
1 package can be updated.
0 updates are security updates.
Last login: Thu Aug 16 15:41:58 2012 from 10.0.65.153
Environment:
LANG=en_US.UTF-8
USER=blyman
LOGNAME=blyman
HOME=/home/blyman
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
MAIL=/var/mail/blyman
SHELL=/bin/bash
SSH_CLIENT=::1 43599 50505
SSH_CONNECTION=::1 43599 ::1 50505
SSH_TTY=/dev/pts/16
TERM=xterm
DISPLAY=localhost:10.0
Running /usr/bin/xauth remove unix:10.0
/usr/bin/xauth add unix:10.0 MIT-MAGIC-COOKIE-1 79aa9275ced418dd445d9798b115d393
Run Code Online (Sandbox Code Playgroud)
看看那里的最后三行。我很幸运地DISPLAY设置了,并且从/usr/bin/xauth.
从那里开始,将 my/usr/bin/xauth移到/usr/bin/xauth.old,断开连接ssh并停止sshd,然后启动sshd并ssh返回到本地主机是孩子的游戏。
当/usr/bin/xauth消失时,我没有看到DISPLAY反映在我的环境中。
这里没有什么精彩的事情发生。大多数情况下,我很幸运地选择了一种理智的方法来尝试在我的本地机器上重现它。
ken*_*orb 55
确保:
xauth在服务器上安装(请参阅:xauth info/ xauth list)。在服务器上,您的/etc/ssh/sshd_config文件有以下几行:
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
Run Code Online (Sandbox Code Playgroud)在客户端,您的~/.ssh/config文件有以下几行:
Host *
ForwardAgent yes
ForwardX11 yes
Run Code Online (Sandbox Code Playgroud)在客户端,您已经安装了 X 服务器(例如 macOS:XQuartz;Windows:Xming)。
然后要使用 SSH 进行 X11 转发,您需要添加-X到您的ssh命令中,例如
ssh -v -X user@host
Run Code Online (Sandbox Code Playgroud)
然后通过以下方式验证您DISPLAY的不为空:
echo $DISPLAY
Run Code Online (Sandbox Code Playgroud)
如果是,则使用 ssh ( -v) 的详细参数,检查是否有任何警告,例如
debug1: No xauth program.
Warning: untrusted X11 forwarding setup failed: xauth key data not generated
Run Code Online (Sandbox Code Playgroud)
如果您有如上所示不受信任的 X11,请尝试使用-Yflag(如果您信任主机):
ssh -v -Y user@host
Run Code Online (Sandbox Code Playgroud)
请参阅:使用 -X 进行 ssh 时,“警告:不受信任的 X11 转发设置失败:未生成 xauth 密钥数据”是什么意思?
如果您有警告: No xauth data,您可以尝试生成一个新.Xauthority文件,例如
xauth generate :0 . trusted
xauth list
Run Code Online (Sandbox Code Playgroud)
如果您收到与上述不同的警告,请按照进一步的线索进行操作。
小智 24
解决方法是将此行添加到您的/etc/ssh/sshd_config:
X11UseLocalhost no
Run Code Online (Sandbox Code Playgroud)
https://joshua.hoblitt.com/rtfm/2013/04/how_to_fix_x11_forwarding_request_failed_on_channel_0/
小智 6
ssh -X 以在远程服务器上获得 GUI 环境安装以下所有内容。在 Window 上,安装Xming. 在终端的 Ubuntu 上,使用sudo apt install来安装ssh xauth xorg.
sudo apt install ssh xauth xorg
Run Code Online (Sandbox Code Playgroud)
转到包含ssh_config文件的文件夹,我的是/etc/ssh.
ssh_config以管理员身份编辑(USE sudo)。里面ssh_config,删除哈希#中的台词ForwardAgent,ForwardX11,ForwardX11Trusted,和相应的参数设置yes。
# /etc/ssh/ssh_config
Host *
ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes
Run Code Online (Sandbox Code Playgroud)
在ssh_config文件中,去掉 和 前面的哈希#,Port 22并在文件Protocol 2末尾追加一个新行来说明 xauth 文件的位置,XauthLocation /usr/bin/xauth,记得写自己的 xauth 文件路径。
# /etc/ssh/ssh_config
# IdentifyFile ...
Port 22
Protocol 2
# Cipher 3des
# ...
# ...
...
...
GSSAPIDelegateCredentials no
XauthLocation /usr/bin/xauth
Run Code Online (Sandbox Code Playgroud)
现在既然我们已经完成了ssh_config文件的编辑,当我们离开编辑器时保存它。现在转到文件夹~或$HOME,附加export DISPLAY=localhost:0到您的.bashrc文件并保存它。
# ~/.bashrc
...
...
export DISPLAY=localhost:0
Run Code Online (Sandbox Code Playgroud)
我们快完成了。重新启动 bash shell,打开Xming程序并使用ssh -X yourusername@yourhost. 然后享受GUI环境。
ssh -X yourusername@yourhost
Run Code Online (Sandbox Code Playgroud)
问题也出在 Windows 上的 Ubuntu 子系统中,链接位于
https://gist.github.com/DestinyOne/f236f71b9cdecd349507dfe90ebae776
如果您要从 Windows (10) 到 Linux 系统进行 ssh - 帮自己一个忙,使用像 Putty 这样的 SSH 客户端(常规 ssh -X 等不起作用)。
第 1 步:在 Windows 中安装 XServer :示例 XMing 服务器(侦听 localhost:0.0)
步骤2:在putty中启用X11转发
第 3 步:连接到远程 Linux 服务器
确保 Linux 服务器中满足此处的所有条件 - 即 X11Forwarding 为 yes 并且 xauth 存在,如答案https://unix.stackexchange.com/a/12772/121634中所述
启动 XClock 并等待一分钟,以便 Windows 计算机上出现显示
注意 - 如果您要从此 Linux 服务器连接到另一台服务器并希望将 X11 转发回 Windows,则只需使用 ssh -X 连接到链中的下一个服务器。
那是
[Windows] Putty(带 X11forwarding)--> [Server1](xclock 有效)--> ssh -X [Server 2](xclock 有效)
| 归档时间: |
|
| 查看次数: |
1179511 次 |
| 最近记录: |