如何通过图形界面连接云中的主机

本文虽然是针对Oracle云写的,但也适用于其他云主机。
本文主要参照一下文档:
Running Graphical Applications Securely on Oracle Cloud Infrastructure
这个文档是针对Linux 7的,而我的环境是Linux 6。

首先我建了一个数据库云服务,版本12.2.0.1,OS是OL 6u10.
在这里插入图片描述
visudo可以看到定义如下:

%opc    ALL=(ALL)       NOPASSWD: ALL

因此把oracle用户加入opc组,使其具有sudo权限:

[root@eus opc]# usermod -a -G opc oracle
[root@eus opc]# id oracle
uid=101(oracle) gid=1001(oinstall) groups=1001(oinstall),54323(opc),1006(asmdba),1003(dba),1002(dbaoper)
[root@eus opc]#

退出并重新登录,可使新的组生效。
如果不想退出,可以:

newgrp - opc

在云主机上的设置:
使sshd不使用localhost来启用X11,并且X11Forwarding设置为Yes:

vi /etc/ssh/sshd_config
# add below line
X11UseLocalhost no
service sshd restart or systemctl restart sshd 

安装xauth和xterm,后者仅用于测试:

sudo yum -y install xauth xterm

确认安装:

$ rpm -qa|egrep "xauth|xterm"
xorg-x11-xauth-1.0.9-1.el7.x86_64
xterm-295-3.el7.x86_64

在客户端安装X Server,我选择的是Xming。按照文档一步步装就好了。此处略。

配置Putty SSH X11会话,其实就是启用X11 forwarding。按照文档做就好。此处略。
如果客户端是Linux,就很简单,直接ssh -X即可。

第一次验证失败了,确认了DISPLAY是设置正确的。:

[opc@eus ~]$ ping -c3 $(hostname)
PING eus.sub06110143221.eusvcn.oraclevcn.com (10.0.1.2) 56(84) bytes of data.
64 bytes from eus.sub06110143221.eusvcn.oraclevcn.com (10.0.1.2): icmp_seq=1 ttl=64 time=0.028 ms
64 bytes from eus.sub06110143221.eusvcn.oraclevcn.com (10.0.1.2): icmp_seq=2 ttl=64 time=0.033 ms
64 bytes from eus.sub06110143221.eusvcn.oraclevcn.com (10.0.1.2): icmp_seq=3 ttl=64 time=0.031 ms

--- eus.sub06110143221.eusvcn.oraclevcn.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.028/0.030/0.033/0.006 ms

[root@eus opc]# echo $DISPLAY
eus:11.0

[opc@eus ~]$ xterm
PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused
xterm Xt error: Can't open display: eus:11.0

原因是我Windows端的X Server即X Ming未启动,启动XLaunch即可。

[opc@eus ~]$ xterm &
[1] 68778

看到以下的界面,说明所有配置成功了:
在这里插入图片描述
可是我们的目的是使用oracle用户下的dbca等程序。所以切换到oracle用户下试试:

[root@eus stage]# su - oracle

[oracle@eus ~]$ export DISPLAY=eus:11.0
[oracle@eus ~]$ xterm
PuTTY X11 proxy: Unsupported authorisation protocol
xterm Xt error: Can't open display: eus:11.0

失败了。查了文档,发现X11 Forwarding不支持su。因此我们需要配置oracle用户的直接登录,也就是需要配置oracle用户的私钥。我们把opc用户下的私钥拷贝过来即可。

[oracle@eus ~]$ cd ~/.ssh
[oracle@eus .ssh]$ pwd
/home/oracle/.ssh

[oracle@eus .ssh]$ sudo cat ~opc/.ssh/authorized_keys >> authorized_keys

这回好了:

login as: oracle
Authenticating with public key "rsa-key-20170408"
/usr/bin/xauth:  file /home/oracle/.Xauthority does not exist
[oracle@eus ~]$ xterm
Warning: Cannot convert string "nil2" to type FontStruct

DBCA也可以了:
在这里插入图片描述
不过X11 forwarding是很慢的。下会要试一下VNC。

参考:
https://unix.stackexchange.com/questions/12755/how-to-forward-x-over-ssh-to-run-graphics-applications-remotely

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值