【问题标题】:ssh forwarding from mac to ubuntu doesn't work从 mac 到 ubuntu 的 ssh 转发不起作用
【发布时间】:2020-10-03 14:02:06
【问题描述】:

我正在尝试使用 mac 上的 ssh 转发功能在本地显示远程 GUI 应用程序。

在 Mac 上,我安装了官方的 xserver XQaurtz,设置如下。

$ cat ~/.ssh/config
Host *
    XAuthLocation /opt/X11/bin/xauth
    ForwardAgent yes
    ForwardX11 yes

然后我用“ssh -v -X user@remote_machine”登录ubuntu机器,然后用xclock进行测试。

$ ssh -v -X user@remote_machine
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data ~/.ssh/config
debug1: /Users/bwu/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: /etc/ssh/ssh_config line 52: Applying options for *
debug1: auto-mux: Trying existing master

在远程机器上,由于 $DISPLAY 为空,xclock 无法启动。

$ xclock
Error: Can't open display:

我又做了两个测试。

  1. 从同一个 mac,ssh 登录到另一台 centos 7 机器,它正在工作。 $ cat /etc/ssh/sshd_config X11Forwarding 是 X11DisplayOffset 0

  2. 从 ubuntu 主机, ssh 登录到上面的 ubuntu 机器,它正在工作。 $ cat /etc/ssh/sshd_config X11Forwarding 是 X11DisplayOffset 0

所以我们得到了以下结果。

mac to centos, working
ubuntu to ubuntu, working
mac to ubuntu, not working
Test 1 indicates the issue might locate on remote ubuntu machine.
Test 2 indicates the issue might locate on local mac machine.

这有什么问题?我错过了什么吗?

【问题讨论】:

  • 你可以试试可信的X11转发吗? ssh -v -Y user@remote_machine
  • 我以为我之前尝试过,但都没有用。刚刚又试了一次,'ssh -v -Y' 显示了更多信息,然后我尝试了'ssh -v -X',这次它可以工作了。它还显示了更多消息,尤其是“debug1: Requesting X11 forwarding with authentication spoofing。”。以前的尝试从未看到此“请求 X11”消息。对此感到困惑,不知道发生了什么。
  • 它不再工作了,疯了。 >$ ssh -v -Y user@remote_machine >OpenSSH_7.9p1, LibreSSL 2.7.3 >debug1: 读取配置数据 /Users/bwu/.ssh/config >debug1: /Users/bwu/.ssh/config line 1: Applying * >debug1 的选项:读取配置数据 /etc/ssh/ssh_config >debug1:/etc/ssh/ssh_config 第 48 行:应用 * >debug1 的选项:/etc/ssh/ssh_config 第 52 行:应用 * >debug1 的选项:自动多路复用器:尝试现有的主 >$ xclock >错误:无法打开显示:本地主机:0.0 >$ echo $DISPLAY >本地主机:0.0

标签: macos ubuntu ssh centos


【解决方案1】:

关于这个问题的进一步更新。我注意到 x11 转发在 centos 或 ubuntu(来自我的 macbook)上“随机”不起作用,但几个小时后它可能会再次起作用。

我检查了centos和ubuntu上的sshd配置,没什么特别的,它们在x11转发部分是一样的。我不知道为什么。

X11Forwarding yes
X11DisplayOffset 0
#X11UseLocalhost yes

【讨论】:

    【解决方案2】:

    这是一个可行的解决方案。我有同样的问题,这就是我解决它的方法。请尝试以下解决方案。

    首先找到 DISPLAY 变量。

    如果你以普通用户的身份输入,那么在你的 mac 中

    echo $DISPLAY
    

    那么你会得到类似下面的东西。

    /private/tmp/com.apple.launchd.0aQYNoXMFK/org.xquartz:0
    

    然后尝试类似

    xeyes
    

    查看转发是否有效。您可以尝试其他应用,但我喜欢这个。

    现在您知道您的显示器正在工作

    现在,如果您想尝试与 root 相同的操作(请不要跳我,我知道你们中的一些人都强烈反对 root 访问)echo $DISPLAY,但如果不起作用

    然后在您的根提示符下执行以下操作

    export DISPLAY=/private/tmp/com.apple.launchd.0aQYNoXMFK/org.xquartz:0
    

    与您在普通用户帐户中找到的相同。然后复制你的 .Xauthority 在 /Users/普通用户/.Xauthority 到 /var/root/。

    .Xauthority 文件已经存在,但这会覆盖它。

    cp /Users/normal user/.Xauthority /var/root/
    

    当然导出可能会起作用,但执行上述操作并没有什么坏处。

    现在试试下面的。

    echo $DISPLAY
    

    您应该会看到以下内容

    /private/tmp/com.apple.launchd.0aQYNoXMFK/org.xquartz:0
    

    如果您从普通用户提示符ssh 进入 Ubuntu,那么您不需要执行 root 部分,但是因为我使用 root 将 ssh 进入我的 Ubuntu 系统,所以我经常必须这样做。

    然后当你 ssh 进入 Ubuntu 类型时

    echo $DISPLAY
    

    你会看到类似下面的内容

    localhost:10.0
    

    如果您已完成所有其他操作,例如转发等,上述方法将起作用。

    同样,如果您想在 Ubuntu 中使用 root 并且如果 echo $DISPLAY 没有产生任何响应,

    然后尝试以下操作(假设您在 root 提示符下)。

    cp /home/user name/.Xauthority /root/.Xauthority
    

    现在试试

    echo $DISPLAY
    

    你会看到类似下面的内容

    localhost:10.0
    

    为了好玩尝试

    xeyes
    

    当然你也可以试试 xclock 或者其他的

    它适用于我的情况。希望这会有所帮助,并且可以解决像上面这样的问题,或者像我这样的问题,有人遇到过这个问题,他花了几个小时在这个问题上,同时像我一样挠头并试图拔掉头发:-))。

    【讨论】:

      猜你喜欢
      • 2013-05-30
      • 2015-04-26
      • 2011-12-30
      • 2014-02-26
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 2019-03-11
      相关资源
      最近更新 更多