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的剪切板就直接是那个文件的内容了.

posted @ 2021-05-30 12:25  Tokubara  阅读(1104)  评论(0编辑  收藏  举报