X11 connection rejected - Linux

Table of Contents

大家好,小弟今早連線學校雲端 Windows 10 的 MobaXterm 連SSH到學校實驗室Linux
伺服器(Scientific Linux),開啟我的模擬軟體時,突然出現底下的錯誤訊息:

X11 connection rejected because of wrong authentication
couldn't connect to display "localhost:10.0"

明明 MobaXterm 上方就提到

X11-forwarding 打勾
DISPLAY 打勾

後來我用自己的 MacBook air 用 SSH 指令連線,並開啟模擬軟體,也出現同樣錯誤。

ssh -l username -X IP

重要的是我昨晚凌晨兩點還可以順利開啟模擬軟體,不管是在 Win10 還是 MacOS 都可。
真的不清楚是怎麼回事了。怎麼會突然出問題呢?

-----

後來我查了 StackExchange 文章:https://reurl.cc/vn14pN

裡頭提到檢查當前 $DISPLAY 是否有在 ~/.Xauthority 中,

於是我輸入 echo $DISPLAY,得到:

localhost:10.0

然後輸入 xauth list,出現一串東西,其中看起來跟 $DISPLAY 比較相似的是:

localhost.localdomain/unix:10 MIT-MAGIC-COOKIE-1
204616784711287df21f92540e9f85ee

我不確定這是不是就是 localhost:10.0,於是我想說就當作不是吧。
就直接自己新建一個好了。

xauth add $DISPLAY - `mcookie`

結果出現

xauth: (argv):1: key contains odd number of or non-hex characters

重新輸入 xauth list,發現內容好像沒什麼變化....

---

後來我看到另一篇文章"xauth not creating .Xauthority file"
https://superuser.com/questions/806637/xauth-not-creating-xauthority-file

我想起如果把 ~/.Xauthority 移除,那照理說如果我輸入需要X11的指令,例如
xclock,那麼系統應該會自己建立 ~/.Xauthority?於是我輸入

mv .Xauthority old.Xauthority

然後再登出、登入並輸入 xclock,發現還是出現問題....

X11 connection rejected because of wrong authentication.
Error: Can't open display: localhost:10.0

並且在 /home/username 目錄中,系統並沒有自動生成 .Xauthority,覺得很奇怪。

----- 相關資訊補充 -----

另外我的 ~/.Xauthority 確實是在 /home/username 底下,其權限為600。
至於目錄本身則是 700。

也有輸入 yum install xorg-x11-xauth,說是最新版本不需更新

Package 1:xorg-x11-xauth-1.0.9-1.el7.x86_64 already installed and
latest version

Nothing to do

我也有確認 SSH 伺服器之 X Forwarding 設定

$ cat /etc/ssh/sshd_config | grep X11Forwarding
X11Forwarding yes(確實是yes)

我也有確認 SSH 客戶端(MacOS)之 X Forwarding 設定

$ cat /etc/ssh/ssh_config | grep ForwardX11
ForwardX11 yes
ForwardX11Trusted yes

輸入ssh -v -X user@host,出現

ssh: Could not resolve hostname username: nodename nor servname
provided, or not known

我也有在 sshd_config 中添加 AddressFamily inet 强制 OpenSSH 只使用 IPv4

究竟該怎麼辦才好呢 QQ 這樣下去我不知道怎麼做研究了 QAQ..

--

All Comments

Bennie avatarBennie2019-09-18
首先,你先ping host看有沒有ping到
Faithe avatarFaithe2019-09-22
打給我吧
Xanthe avatarXanthe2019-09-25
小弟能力有限,請其他大大幫忙!!
Dora avatarDora2019-09-29
重啟 xserver ?