简介
X11,X Window System,以位图方式显示软件窗口,为 GUI 环境提供基本框架
安装
查看是否已安装 X11
dpkg -l | grep xserver-xorg-core
安装 X11,大概需要 17 - 222 MB(前者是在服务器上装,后者在自己的 WSL 装,具体视情况而定)
sudo apt-get install xorg
sudo apt-get install xauth
sudo apt-get install openbox
sudo apt-get install xserver-xorg-legacy
查看是否开启 X11 转发
cat /etc/ssh/sshd_config | grep X11Forwarding
安装 xclock
sudo apt install x11-apps
初试
Windows 使用 MobaXterm
xclock
跳板机
许多生产服务器是这样连接的:本机 → 多台跳板机 → 服务器
配置映射可阅读:How to forward an X11 client through a Jump Host back to a PC with an X Emulator
但最简单的是让运维开个外网 IP 让直接连接
Error: Can’t open display:
修改 sshd 配置文件
sudo vim /etc/ssh/sshd_config
保证该配置文件有
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
PermitTunnel yes
重启 sshd 服务
service sshd restart
重新连接 SSH
查看转发,有的话就 OK 了
echo $DISPLAY
xclock
推荐阅读:sshd_config 参数详解
切换用户无法显示
切换用户
sudo su - xxx
时钟
xclock
报错
MoTTY X11 proxy: Unsupported authorisation protocol
Error: Can't open display: xxx:10.0
Ctrl + D 退回到能显示的用户,输出配置并复制
xauth list $DISPLAY
testpy-10-13-128-183/unix:10 MIT-MAGIC-COOKIE-1 0bf3f86382d0315c5f902384dbd7571e
echo $DSIPLAY
localhost:10.0
切换用户
sudo su - xxx
添加配置
xauth add testpy-10-13-128-183/unix:10 MIT-MAGIC-COOKIE-1 0bf3f86382d0315c5f902384dbd7571e
时钟可以正常显示
xclock
如果 xauth add 那步失败
sudo vim /etc/X11/Xwrapper.config
把
allowed_users=console
改成
allowed_users=anybody
参考文献
- How to install X11/xorg?
- linux服务器通过X11实现图形化界面显示
- ServerGUI - Community Help Wiki
- How to check if the X11 display manager is installed?
- How do I fix a “cannot open display” error when opening an X program after ssh’ing with X11 forwarding enabled? - Super User
- 使用x11 forwarding显示X Windows
- How to forward an X11 client through a Jump Host back to a PC with an X Emulator
- sshd_config
- macOS使用XQuartz支持X11实现Linux图形化界面显示
- xorg - PuTTY X11 forwarding: Unsupported authorisation protocol
- Can’t start X11 applications after “su” or “su -” to another user