ssh打開X11 forwarding(parallel desktop在ssh中ubuntu與mac共享剪切板)


我用ssh連上了ubuntu虛擬機, 嘗試xclip命令時, 輸入ls | xclip -sel c, 得到報錯: Error: Can't open display: (null). 搜索后, 發現好像和X11和DISPLAY有關. 還說ssh應該打開-X選項. 可用ssh -X連接, 還是不行.

現在來說說, 是怎么行的. 我不知道原理, 可能有的步驟是冗余的.

參考這個回答.

先說怎么判斷是否work? echo $DISPLAY, 如果輸出不為空, 那就可以. 或者可以再次運行ls | xclip -sel c, 不報錯就是可以的

server(ubuntu)

ubuntu的/etc/ssh/sshd_config

X11Forwarding yes
X11DisplayOffset 10

which xauth顯示xauth已安裝

systemctl restart sshd

但是還不夠.

client(mac)

我用ssh -X -v連接, 加上了-v, debug選項, 在進入ubuntu之前, 給了我這個與X11 forwarding有關的報錯:

debug1: Remote: /home/parallels/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: /home/parallels/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: No xauth program.
Warning: untrusted X11 forwarding setup failed: xauth key data not generated

關鍵的報錯是No xauth program, 而且注意到, 前面沒有remote. 所以它說的是mac. 於是參考回答1, 回答2. 我沒完全按它們的步驟. 只做了一步:

編輯/etc/ssh/ssh_config, 在最后Host加了XAuthLocation /opt/X11/bin/xauth, 至於后面這個路徑怎么來的, 是which xauth得到的.

然后就可以了, 從ssh啟動firefox, 雖然非常卡, 但畢竟是可以了.

后記

我沒有想到的是, 做完上面這件事, 在ssh中, ubuntu竟然直接可以與mac共享剪切板了(注意, 是在ubuntu已經安裝了Parallels Tools之后). 舉例子, ssh中, cat file.txt | xclip -sel c, mac的剪切板就直接是那個文件的內容了.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM