9

交叉发布

环境细节

服务器 /etc/ssh/sshd_config 的相关位:

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no

客户端 $HOME/.ssh/config 的相关位:

Host *
    XAuthLocation /opt/X11/bin/xauth
    ForwardX11 yes
    ForwardX11Trusted yes

在 macOS High Sierra 上使用 XQuartz。

问题

我正在启动一个流浪的 Ubuntu 18.04 虚拟机。我在用户之外添加了第二个vagrant用户。

ssh -X vagrant@ubuntu-bionic xclock

当我以用户身份登录时,我可以让 X11Forwarding 工作vagrant。当我以用户身份登录时,我无法让 X11Forwarding 工作ops

ssh -X ops@ubuntu-bionic xclock

X11 forwarding request failed on channel 0
Error: Can't open display:

我希望能够让它与ops用户一起工作。来自客户,$DISPLAY有价值。当我登录时vagrant$DISPLAY有一个值。当我以 身份登录时ops$DISPLAY未设置。如果我设置$DISPLAY为与vagrant用户匹配,我会得到同样的错误:

Error: Can't open display: localhost:10.0

什么时候X11UseLocalhost yes

Error: Can't open display: ubuntu-bionic:10.0

什么时候X11UseLocalhost no

ops如果我以和 then身份登录sudo su - vagrant,则$DISPLAY保持未设置。如果我登录为vagrant然后sudo su - ops$DISPLAY则被继承。

我缺少什么让这个工作?我已经xhost +在每个用户(包括sudo -s root xhost +)中运行它仍然无法正常工作。

如果我添加-vv到我的 ssh 命令,我会在连接时看到此消息vagrant

X11 forwarding request accepted on channel 0

并作为ops

Remote: X11 forwarding disabled in user configuration file.
X11 forwarding request failed on channel 0
4

2 回答 2

1

我不明白整个话题,但是对于我非常相似的情况,它有助于创建用户s~/.Xauthorityfile. I copied it from the vagrant user的主目录,然后设置新的所有权。

于 2018-09-12T18:54:01.053 回答
0

XQuartz 2.8.1在带有(xorg-server 1.20.11) 的macOS BigSur 上:

将以下内容设置为我为我Vagrantfile解决的问题(对于ubuntu 20.04):

  config.vm.provision "shell",
    inline: "apt-get update && apt-get upgrade -y && apt-get install xauth -y"
  config.ssh.forward_agent = true
  config.ssh.forward_x11 = true

整个 Vagrantfile 将是:

Vagrant.require_version ">= 2.2.3"

Vagrant.configure("2") do |config|
  config.vm.provider "virtualbox" do |v, override|
    override.vm.box = "bento/ubuntu-20.04"
  end
  config.vm.provision "shell",
    inline: "apt-get update && apt-get upgrade -y && apt-get install xauth firefox firefox-geckodriver -y"
  config.ssh.forward_agent = true
  config.ssh.forward_x11 = true
end

允许firefox -no-remote https://stackoverflow.com/通过 X 服务器运行。添加该-no-remote标志是因为它似乎可以减少延迟。

受到Josphat Mutai的How to enable and use SSH X11 Forwarding on Vagrant Instances指南的启发。

于 2021-12-29T17:20:40.677 回答