我们新安装Centos时可能会选择最小安装,不安装桌面环境,但是后期使用过程中突然需要运行可视化的软件,例如火狐浏览器,此时因为没有桌面环境支持,而需要通过ssh X11转发界面。Centos 7 最小化安装状态下默认没有开启xshell的转发功能,我们需要手动设置并安装相应组件。
当我们使用MobaXterm通过SSH连接到Centos时,会发现X11-forwarding不支持状态如下图所示
修改SSH配置文件sshd_config
编辑 /etc/ssh/sshd_config 文件
将 X11Forwarding 和 X11UseLocalhost 前面的 # 去掉,并将 X11Forwarding 设置为 yes,X11UseLocalhost 设置为 no
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#禁止将X11转发请求绑定到本地回环地址上
X11UseLocalhost no
1
2
3
4
5
6
7
安装 X11 Forwarding 相关软件
运行安装命令
sudo yum install xorg-x11-xauth xorg-x11-fonts-* xorg-x11-font-utils xorg-x11-fonts-Type1 xclock
1
重启 sshd 服务,并重新SSH连接
重启ssh服务
sudo systemctl restart sshd.service
1
再次通过MobaXterm连接,会发现已经支持了X11-forwarding了
验证
运行软件xclock,弹出窗口证明成功
export DISPLAY=192.168.120.213:0.0