![xhost:无法打开显示“桌面:0”](https://linux22.com/image/186978/xhost%EF%BC%9A%E6%97%A0%E6%B3%95%E6%89%93%E5%BC%80%E6%98%BE%E7%A4%BA%E2%80%9C%E6%A1%8C%E9%9D%A2%EF%BC%9A0%E2%80%9D.png)
更新 1:我没有使用 SSH。我正在使用本地机器。
更新 2:我重新启动了 X,并注意到我要导出到的 Xauthority 文件实际上正在更新:
$ sudo systemctl restart display-manager
$ ls /run/user/1000/gdm/Xauthority*
-rwx------ 1 mona mona 96 Jan 25 16:07 /run/user/1000/gdm/Xauthority
另外,在我重新启动 X 后,其他两个 Xauthority 文件,即/run/user/1000/gdm/Xauthority-c
和/run/user/1000/gdm/Xauthority-l
,都消失了,如下所示:
$ fd Xauthority /
/run/user/1000/gdm/Xauthority
重新启动后我可以调用 xauth:
$ xauth
Using authority file /run/user/1000/gdm/Xauthority
xauth>
下列的尝试远程运行程序时出现“无效的 MIT-MAGIC-COOKIE-1 密钥”我试过:
[9080:9072 0:2035] 02:14:50 Mon Jan 25 [mona@goku:pts/0 +1] ~/research/code/vision/integration
$ export DISPLAY=desktop:0
18838/31772MB(vision)
进而:
$ xhost +local:
xhost: unable to open display "desktop:0"
我该如何解决这个问题?
$ lsb_release -a
LSB Version: core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
另一个类似的例子:
$ xclock
Error: Can't open display: desktop:0
更多细节:
$ xclock
Error: Can't open display: desktop:0
27296/31772MB
[3266:3258 3:2008] 02:54:16 Mon Jan 25 [mona@goku:pts/0 +1] ~
$ export DISPLAY=":0.0"
26016/31772MB
[3266:3258 3:2009] 02:57:24 Mon Jan 25 [mona@goku:pts/0 +1] ~
$ xclock
Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0.0
$ export DISPLAY=":0"
26238/31772MB
[3266:3258 3:2011] 02:57:40 Mon Jan 25 [mona@goku:pts/0 +1] ~
$ xclock
Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0
$ xhost +mona
Invalid MIT-MAGIC-COOKIE-1 keyxhost: unable to open display ":0"
$ firefox
Invalid MIT-MAGIC-COOKIE-1 keyUnable to init server: Could not connect: Connection refused
Error: cannot open display: :0
$ xclock
Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0
25694/31772MB
[3266:3258 3:2026] 03:04:35 Mon Jan 25 [mona@goku:pts/0 +1] ~
$ export DISPLAY=desktop:0
25694/31772MB
[3266:3258 3:2027] 03:04:49 Mon Jan 25 [mona@goku:pts/0 +1] ~
$ xclock
Error: Can't open display: desktop:0
另外,我在 Xauthority 文件中有奇怪的字符:
$ xrandr | nc termbin.com 9999
Invalid MIT-MAGIC-COOKIE-1 keyCan't open display :0
21618/31772MB
[9136:3258 0:2002] 03:49:16 Mon Jan 25 [mona@goku:pts/2 +1] ~
$ fd Xauthority /
/run/user/1000/gdm/Xauthority
/run/user/1000/gdm/Xauthority-c
/run/user/1000/gdm/Xauthority-l
22048/31772MB
[9136:3258 0:2003] 03:51:26 Mon Jan 25 [mona@goku:pts/2 +1] ~
$ cat /run/user/1000/gdm/Xauthority-c
22048/31772MB
[9136:3258 0:2004] 03:51:49 Mon Jan 25 [mona@goku:pts/2 +1] ~
$ cat /run/user/1000/gdm/Xauthority-l
22081/31772MB
[9136:3258 0:2005] 03:51:58 Mon Jan 25 [mona@goku:pts/2 +1] ~
$ cat /run/user/1000/gdm/Xauthority
gokuMIT-MAGIC-COOKIE-1R��9��s{�H��H�l��gokuMIT-MAGIC-COOKIE-1R��9��s{�H��H�l22081/31772MB
[9136:3258 0:2006] 03:52:03 Mon Jan 25 [mona@goku:pts/2 +1] ~
另外,将其设置为找到的 Xauthority 文件并不能解决问题:
$ export XAUTHORITY=/run/user/1000/gdm/Xauthority
22022/31772MB
[9136:3258 0:2010] 03:54:31 Mon Jan 25 [mona@goku:pts/2 +1] ~
$ xclock
Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0
我的uid 1000:
uid=1000(mona) gid=1000(mona) groups=1000(mona),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),131(lxd),132(sambashare)
我也有这些关于xauth
:
$ xauth info 权限文件:/run/user/1000/gdm/Xauthority 新文件:否 文件锁定:否 条目数量:2 已兑现的更改:是 所做的更改:否 当前输入:(argv):1 21740/31772MB [11979 :11971 0:2016] 05:26:34 Mon Jan 25 [mona@goku:pts/0 +1] ~ $ xauth list goku/unix: MIT-MAGIC-COOKIE-1 SECRET_KEY #ffff#676f6b75#: MIT-MAGIC -COOKIE-1 SECRET_KEY