Pycharm ssh远程调试报错: cannot connect to X server的解决方法

  1. 服务器端
    安装 X11 Forwarding 相关软件
sudo yum install xorg-x11-xauth xorg-x11-fonts-* xorg-x11-font-utils xorg-x11-fonts-Type1 xclock

启用 X11 Forwarding
sudo vim /etc/ssh/sshd_config
将 X11Forwarding 和 X11UseLocalhost 前面的 # 去掉,并将 X11Forwarding 设置为 yes,X11UseLocalhost 设置为 no

1 #AllowAgentForwarding yes
2 #AllowTcpForwarding yes
3 #GatewayPorts no
4 X11Forwarding yes
5 #X11DisplayOffset 10
6 X11UseLocalhost no

保存时出现readonly文件解决方案
1.在退出时输入如下指令:
:w !sudo tee %
2.看到如图信息后回车:

image.png

3.看到如图信息后,输入字母L:
image.png

4.然后就回到了编辑界面,这是输入如图信息
:q
5.回车后就退出了。这个时候我们新编辑的内容就被保存下来。
6.建议大家还是不用直接编辑readonly文件了,本方法只是一个补救方法,希望对大家有用。

重启 sshd 服务
sudo systemctl restart sshd.service

2 MobaXterm连接

Pycharm ssh远程调试报错: cannot connect to X server的解决方法_第1张图片
image.png

注意到 X11-forwarding 和 DISPLAY 这两项都打上了绿色的勾,代表设置成功了。

  1. 验证
    在服务器端运行一个 GUI 程序,如
    xclock
    这时候,你在本地 (Windows 端),就可以看到相应的图形化界面(窗口)
    Pycharm ssh远程调试报错: cannot connect to X server的解决方法_第2张图片
    image.png

4 配置pycharm
在服务器终端中输入:
echo $DISPLAY
得到远程终端的display number,如下图中的:localhost:11.0

image.png

然后在pycharm中选择Run->Edit,打开Edit Configuration settings,在Environment的Environment variables中添加环境变量的display number:“DISPLAY = localhost:11.0”
image.png

5配置mobaxterm(不然报错ASSERT: "false" in file qasciikey.cpp, line 501)
moba-xterm > settings > x11 Settings > "Unix-compatible keyboard" 的复选框不要勾选,然后按照提示会自动重启x server,重新在pycharm运行代码就可以了

参考链接:
https://www.cnblogs.com/ipaomi/p/7830778.html
https://www.cnblogs.com/dev-lluo/p/11327626.html
https://blog.csdn.net/linghu8812/article/details/101097882
https://blog.csdn.net/xinyx/article/details/80514971
https://blog.csdn.net/qxqxqzzz/article/details/104942021

你可能感兴趣的:(Pycharm ssh远程调试报错: cannot connect to X server的解决方法)