【问题标题】:X11 Forwarding for non-root user not working非root用户的X11转发不起作用
【发布时间】:2018-10-08 19:34:33
【问题描述】:

Cross-Posted

环境细节

服务器 /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

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

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 登录,然后sudo su - vagrant$DISPLAY 仍然未设置。如果我以vagrant 登录,然后sudo su - ops$DISPLAY 将被继承。

让这个工作我缺少什么?我在每个用户(包括sudo -s root xhost +)中运行了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

【问题讨论】:

  • 在ubuntu机器上,~ops/.ssh/config文件里有什么? (即在/home/ops/.ssh/config 中)与vagrant 用户主目录中的那个有什么区别?
  • 服务器vagrant/ops主目录当前没有~/.ssh/config文件。
  • 现在vagrant/ops 都有帖子顶部引用的~/.ssh/config 的内容。还是不行。

标签: vagrant macos-high-sierra x11-forwarding ubuntu-18.04


【解决方案1】:

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

【讨论】:

  • 如果您安装xauth,该文件将被自动创建和填充。
【解决方案2】:

在带有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

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

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

【讨论】:

    猜你喜欢
    • 2011-12-30
    • 2014-10-27
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    • 2015-03-19
    • 2022-01-09
    • 2021-10-21
    • 1970-01-01
    相关资源
    最近更新 更多