DISPLAY 环境变量未设置

cod*_*oda 7 ssh rhel remote amazon-ec2 display

我正在使用 Amazon Linux 2(类似 Fedora/Cent 操作系统的发行版)EC2 计算机以及深度学习 AMI (Amazon Linux 2) 版本 30.1 AMI。

我想在远程实例中使用xclipand 。gedit但如果我输入xclip我得到

Error: Can't open display: (null)
Run Code Online (Sandbox Code Playgroud)

如果我这样做gedit filename我得到

(gedit:6012): Gtk-WARNING **: 00:18:40.117: cannot open display:
Run Code Online (Sandbox Code Playgroud)

我已经浏览过以下链接:

  1. https://github.com/microsoft/WSL/issues/4933
  2. xsel:无法打开显示:(空)
  3. https://askubuntu.com/questions/1035903/how-can-i-get-around-using-xclip-in-the-linux-subsystem-on-win-10
  4. https://www.cyberciti.biz/faq/error-couldnt-open-display-null-and-solution/
  5. https://superuser.com/questions/310197/how-do-i-fix-a-cannot-open-display-error-when-opening-an-x-program-after-sshi
  6. https://www.linuxquestions.org/questions/linux-software-2/xdotool-error-can%27t-open-display-null-4175527094/
  7. https://serverfault.com/questions/765606/xming-cant-open-display-error
  8. https://serverfault.com/questions/425346/cant-open-display-x11-forwarding-cent-os
  9. https://askubuntu.com/questions/305654/xclip-on-headless-server/305681#305681

因而有,

  1. 已安装xauth
  2. 手动将环境变量 DISPLAY 设置为 export DISPLAY="IP_of_remote_machine:0" export DISPLAY="127.0.0.1:0" export DISPLAY=:0.0 export DISPLAY=localhost:0 当我这样做时,我得到
    (gedit:6053): Gtk-WARNING **: 00:23:36.052: cannot open display: 127.0.0.1:0
    
    Run Code Online (Sandbox Code Playgroud)
  3. 我已经尝试过该-Y标志(-X出于安全原因,这不是一个选项,也-X不起作用)
  4. 我已经ForwardX11 yes在客户端~/.ssh/configX11Forwarding yes服务器端添加了/etc/ssh/sshd_config

什么都不起作用。有什么指示吗?

编辑:

我还观看了这个视频,其中说DISPLAY不应进行硬编码。但我的DISPLAY不是自动设置的。当我做 a 时,echo $DISPLAY我什么也得不到。

所以我做了一个xauth list给了我

ip-x-y-x.ec2.internal/unix:10  MIT-MAGIC-COOKIE-1  c84bcd904dd50f7776f667eca7a480f5
Run Code Online (Sandbox Code Playgroud)

所以我做了

export DISPLAY=localhost:10.0
Run Code Online (Sandbox Code Playgroud)

我仍然遇到同样的错误。

cod*_*oda 7

我通过简单地将 $DISPLAY 硬编码为:1 解决了这个问题,

export DISPLAY=:1
Run Code Online (Sandbox Code Playgroud)

在我的.bashrc文件中。

然而,我仍然不明白为什么这有效。这是输出xauth list

ip-172-31-74-230.ec2.internal:1  MIT-MAGIC-COOKIE-1  8a44b41e42cae52c6acd4747763bb985
ip-172-31-74-230.ec2.internal/unix:1  MIT-MAGIC-COOKIE-1  8a44b41e42cae52c6acd4747763bb985
ip-172-31-74-230.ec2.internal:2  MIT-MAGIC-COOKIE-1  e24f36d585762b0c0fe24010b99e448d
ip-172-31-74-230.ec2.internal/unix:2  MIT-MAGIC-COOKIE-1  e24f36d585762b0c0fe24010b99e448d
ip-172-31-74-230.ec2.internal/unix:10  MIT-MAGIC-COOKIE-1  c84bcd904dd50f7776f667eca7a480f5
Run Code Online (Sandbox Code Playgroud)