- change /etc/ssh/sshd_config and restart:
# X11Forwarding yes -> X11Forwarding yes
sudo service sshd restart
-
sudo apt install x11-xserver-utils
-
xhost + # change control access
- 如果报错,参考安装vncserver,但是里面设置的DISPLAY变量是错的,然后设置export DISPLAY=:x.0,x是vnc设置的窗口号(注意运行 vncserver 后的logs, ex: New ‘ubuntu:1 (ubuntu)’ desktop at :1 on machine ubuntu, 这时窗口号是1),然后再执行xhost + 应该就没有问题了
-
echo $DISPLAY # if not none, then success
-
install xming in win10 and start it
-
install xshell in win10 and allow x11 transfering to X DISPLAY: localhost:0.0 in property tunnel
-
if you want use it in pycharm, setup remote interpreter and deployment, then edit run/debug configuration to set environment variables with DISPLAY: localhost:xx.0 (xx same with $DISPLAY in remote server)
-
为了测试是否设置成功,只需要在xshell中ssh到远程服务器,进入python 命令行, 输入以下命令,如果有弹出小窗口,则表示设置成功
import cv2
cv2.namedwindow("img")
附录:vnc 安装教程
https://blog.csdn.net/cunchi4221/article/details/107471665
xshell ssh 连结服务器 后显示:WARNING! The remote SSH server rejected X11 forwarding request.
网上大都建议设置 sshd_config, 我按照要求设置后 ,并无效果,最终找到了是 IPV6 的问题,如果只支持ipv4, 修改sshd_config 中的AddressFamily inet,然后重启ssh service ,问题就应该就解决了