概述
配置
目标主机配置
X11UseLocalhost no
讯享网
重启sshd服务:
讯享网# systemctl restart sshd 或者 # service sshd restart
当然也可以检查设置是否生效:
# sshd -T|grep -i x11 x11displayoffset 10 x11maxdisplays 1000 x11forwarding yes x11uselocalhost no
安装xauth和xterm,后者是测试用的:
讯享网yum -y install xauth xterm
客户端配置
安装X Server软件
客户端在本例中就是Windows主机。客户端需要安装X Server。
可以是Xming或Cygwin/X,本例使用前者。
软件下载和过程略,参考文末的文档即可。
安装完成后,运行XLaunch。

讯享网
配置Putty SSH会话
下载并安装putty。
启用X11 Forwarding:

实际呢,我没有用这个。我用的是命令行,命令行只需指定-X:

D:\vagrant-boxes\OracleLinux\7>vagrant putty -p -- -l oracle -X getting Proxy Configuration from Host...
这里一定要用数据库用户直接登录(-l oracle),不要通过其它用户su或切换。
说明:
以上命令中的-p选项为使用口令登录,因此我在服务器端开启了口令认证,即在文件中设置PasswordAuthentication 为yes。在生产环境中还是建议SSH登录。
讯享网# grep PasswordAuthentication /etc/ssh/sshd_config PasswordAuthentication yes # sudo systemctl restart sshd
如果X11 Forwarding设置成功,登录后可以看到DISPLAY变量已设置:
Using username "oracle". Server refused our key oracle@127.0.0.1's password: Last login: Thu Sep 5 07:10:40 2019 from 10.0.2.2 Welcome to Oracle Linux Server release 7.6 (GNU/Linux 4.14.35-1844.4.5.el7uek.x8 6_64) The Oracle Linux End-User License Agreement can be viewed here: * /usr/share/eula/eula.en_US For additional packages, updates, documentation and community help, see: * http://yum.oracle.com/ /usr/bin/xauth: file /home/oracle/.Xauthority does not exist [oracle@ol7-vagrant ~]$ echo $DISPLAY 127.0.0.1:10.0
讯享网[oracle@ol7-vagrant ~]$ xterm & [1] 6654
看到以下界面就成功了:

X Forwarding走的是SSH的22端口,因此不需额外的防火墙设置。
补充
如果用git bash作为客户端,需要设置如下:
export DISPLAY=localhost:0.0 ssh -XY -v user@remote_server
然后在远端主机的DISPLAY才会正确的设置, 然后图形化程序运行正常:
讯享网$ echo $DISPLAY 10.0.0.5:10.0 $ xterm
参考
- Running Graphical Applications Securely on Oracle Cloud Infrastructure
- SSH onto Vagrant Box With Different Username
- https://unix.stackexchange.com/questions/50698/fastest-remote-x-from-windows
- https://superuser.com/questions//why-is-x11-forwarding-so-inefficient
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/117298.html