VNC是基于RFB(Remote FrameBuffer)的一款开源的远程桌面控制软件。目前,原来的AT&T版本已经不再使用,因为更多有重大改善的分支版本已经出现,像是RealVNC,VNC tight 和UltraVNC。Real VNC 是当前最活跃和强大的主流应用。
一、安装VNC Server
CentOS 6.3默认已经安装vnc与vnc-server,对应的是realvnc的4.1.2版本。
对于没有安装vnc的Linux系统可以:
1、yum安装,CentOS 5.3 yum源自带了vnc与vnc-server;
[root@localhost ~]# yum install vnc
[root@localhost ~]# yum install vnc-server
[root@localhost ~]# yum install vnc-server
2、可以从realvnc官网下载,解压归档后得到两个rpm包,安装vnc-server即可。
=================================================
二、配置VNC Server
VNC Server的配置文件为 /etc/sysconfig/vncservers,在文件末尾添加以下两句:
VNCSERVERS="2:hubery"
VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
#桌面分辨率为800*600 ,阻止图形桌面通过TCP端口 ,不能通过WEB访问vncserver,不能通过不安全的方式从远程登录。
关于参数配置说明:
1:-geometry 表示桌面分辨率,默认为1024x768。
2:-nohttpd 表示不监听HTTP端口(58xx)。
3:-nolisten tcp 表示不监听TCP端口(60xx)
4:-localhost 只允许从本机访问。
5:AlwaysShared 默认只允许一个VNCVIEWER连接,此参数表示同一个显示端口允许多用户同时登录.
6:-depth 表示色深,参数有8,16,24,32.
7: SecurityTypes None 登录不需要密码认证VncAuth默认值,要密码认证。
由于root用户使用的是第一个VNC Server,我们添加Server是从2开始的,所以这里桌面号是2,用户是hubery。
VNC使用的起始端口是5900和5800,桌面号是2时,VNC Viewer访问的端口是5902,WEB方式(java)访问的端口号是5802。
root用户的配置也是这个文件,若要配置需要在文件末尾同样加上类似以上两句。
以上配置,vncserver将在服务启动时打开vncserver :2。
三、防火墙配置
如果不熟悉防火墙iptables,可以直接关掉(重启失效):
[root@localhost ~]# iptables -L
或
[root@localhost ~]# service iptables stop
但一般不建议这样做,我们需要在防火墙里打开某些端口:
[root@localhost ~]# iptables -I INPUT -p tcp --dport 5901:5902 -j ACCEPT
[root@localhost ~]# iptables -I INPUT -p udp --dport 5901:5902 -j ACCEPT
[root@localhost ~]# iptables -I INPUT -p udp --dport 5901:5902 -j ACCEPT
如果是第二个桌面,端口为5801 5802,同样,上述操作在计算机重启之后也会失效,以下操作将配置保存到配置文件,使其永久生效:
[root@localhost ~]# service iptables save
=============================
四、启动VNC Server
在启动Server之前需要给远程控制设置一个访问密码:
[root@localhost ~]# su hubery
[hubery@localhost root]$ vncpasswd
Password:
Verify:
[hubery@localhost root]$ vncserver :2
xauth: creating new authority file /home/hubery/.Xauthority
New 'localhost:2 (hubery)' desktop is localhost:2
Creating default startup script /home/hubery/.vnc/xstartup
Starting applications specified in /home/hubery/.vnc/xstartup
Log file is /home/hubery/.vnc/localhost:2.log
[hubery@localhost root]$
关闭某个vncserver:
vncserver -kill :2
========================================
五、VNC Viewer访问