`ssh -Y` (可信的X11转发)和`ssh -X` (不可信的X11转发)之间有什么区别?

什么是ssh -Y(可信X11转发)和ssh -X(不受信任的X11转发)之间的区别?据我所了解,这与安全有关,但我没有理解它们之间的区别以及何时使用哪个。
4个回答

两个选项都与X11转发有关。这意味着如果你启用了它,你可以通过SSH会话使用图形化客户端(例如,使用Firefox或其他应用)。
如果你使用`ssh -X remotemachine`,远程机器将被视为不受信任的客户端。因此,你的本地客户端发送命令到远程机器并接收图形输出。如果你的命令违反了某些安全设置,你将收到一个错误。
但是,如果你使用`ssh -Y remotemachine`,远程机器将被视为可信任的客户端。这个最后的选项可能会引起安全问题。因为其他图形(X11)客户端可以从远程机器中嗅探数据(截屏、记录按键等恶意行为),甚至可以修改这些数据。
如果你想了解更多关于这些事情的内容,我建议阅读Xsecurity manpage或者X Security extension spec。此外,你可以在你的/etc/ssh/ssh_config文件中查看ForwardX11ForwardX11Trusted选项。

18SSH的man页面使用了不幸的措辞,暗示(至少对我来说)-X是不安全的,而-Y更好。所以感谢您提供的答案。 - Torsten Bronger
1那么,使用“-X”参数,其他客户端就无法窃听或篡改数据了吗? - musiphil
11那么为什么一般情况下会选择使用“-Y”而不是“-X”呢? - Wernight
我有同样的问题(为什么要使用“-Y”),我唯一理解这可能有用的情况是当服务器端的安全控制某种方式没有实施/不兼容时。我还阅读到,转发X11通常是一个强大且危险的工具,应该作为此类工具来处理。 - MakisH
1@Wernight:因为 -X 会破坏许多程序,正如下面 Mitchell 的回答所述。 - serv-inc
8回答“为什么使用-Y而不是-X?”的问题,-X在超时后会删除转发,而-Y则不会。您可以使用ForwardX11Timeout覆盖配置以使用-X选项。 - Seb
ssh -Y remotemachine也等同于ssh -o ForwardX11=yes -o ForwardX11Trusted=yes remotemachine - kyrlon

使用neither当您不需要远程运行X11程序时;使用-X当您需要远程运行X11程序时;如果某个您关心的X11程序在-Y下比-X下表现更好,那么可以假设使用-Y。但是目前(Ubuntu 15.10),-X与-Y是相同的,除非您编辑ssh_config并设置ForwardX11Trusted no。-X最初旨在启用1990年代的X安全扩展,但这已经过时且不灵活,并且会导致某些程序崩溃,因此默认情况下被忽略。
ssh -Y-X都允许您在远程计算机上运行X11程序,并在本地X监视器上显示其窗口。问题在于该程序被允许对其他程序的窗口以及X服务器本身进行哪些操作。
local$ ssh -X remote
remote$ xlogo
# Runs xlogo on remote, but the logo pops up on the local screen.

启用了-Y的信任X11转发。这是历史行为。具有对显示器访问权限的程序被信任可以访问整个显示器。它可以截屏、记录按键并向其他程序的所有窗口注入输入。它还可以使用所有X服务器扩展,包括加速图形等安全风险。这对于平稳运行很好,但对于安全性来说不好。您要相信远程程序与本地程序一样安全。
不受信任的X11转发试图限制远程程序仅访问其自己的窗口,并仅使用相对安全的X部分。听起来很好,但实际上目前效果不佳。
-X的含义目前取决于您的ssh配置。
在Ubuntu 14.04 LTS上,除非您编辑了ssh_config,否则-X和-Y之间没有区别。因为"太多程序在[不受信任]模式下崩溃"。
ubuntu1404$ man ssh
...
 -X      Enables X11 forwarding.  This can also be specified on a per-host
         basis in a configuration file.
         ...
         (Debian-specific: X11 forwarding is not subjected to X11 SECURITY
         extension restrictions by default, because too many programs cur‐
         rently crash in this mode.  Set the ForwardX11Trusted option to
         “no” to restore the upstream behavior.  This may change in
         future depending on client-side improvements.)

ubuntu1404$ grep ForwardX11Trusted /etc/ssh/ssh_config
#   ForwardX11Trusted yes

如果ForwardX11Trusted no,那么-X会启用“不可信任”的转发。否则,-X-Y被视为相同,相信远程具有显示访问权限的程序是友好的。

3这应该是被接受的答案,因为它提供了引入选项的历史背景,并且也没有以“两个选项都与X11转发有关”开头。 - qneill

使用-X选项可以启用X11转发功能。
-X   Enables X11 forwarding.  This can also be specified on a per-host
     basis in a configuration file.

     X11 forwarding should be enabled with caution.  Users with the
     ability to bypass file permissions on the remote host (for the
     user's X authorization database) can access the local X11 display
     through the forwarded connection.  An attacker may then be able
     to perform activities such as keystroke monitoring.

     For this reason, X11 forwarding is subjected to X11 SECURITY
     extension restrictions by default.  Please refer to the ssh -Y
     option and the ForwardX11Trusted directive in ssh_config(5) for
     more information.

选项-Y对应于ssh_config(5)中的ForwardX11Trusted指令,但它更不安全,因为它移除了X11 SECURITY扩展控制。
-Y      Enables trusted X11 forwarding.  Trusted X11 forwardings are not
        subjected to the X11 SECURITY extension controls.

使用-x更安全。
-x   Disables X11 forwarding.

来自人:

Debian特定:
在默认配置中:ForwardX11Trusted yes

-Y 等同于 -X (我认为这个描述更好:-X 使用起来和 -Y 一样简单,但风险相同)


不信任并不意味着机器比可信任的机器更危险,而是表示你谨慎小心,因此更安全。