第一步:查看是否有安装VNCserver
[abc@bogon Desktop]$ rpm -qa |grep vnc
vnc-4.1.2-9.el5
vnc-server-4.1.2-9.el5
如果没有安装,那么需要单独进行安装,然后启动vncserver
一开始要设置一个密码
[root@bogon Desktop]# vncserver
You will require a password to access your desktops.
Password:
Verify:
New 'test.localdomain:1 (root)' desktop is test.localdomain:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/test.localdomain:1.log
第二步:修改/etc/sysconfig/vncservers
[abc@bogon Desktop]$ vi /etc/sysconfig/vncservers
用VI对其进行修改,wq!保存退出
VNCSERVERS="1:root 2:abc"
VNCSERVERARGS[1]="-geometry 800x600 "
VNCSERVERARGS[2]="-geometry 800x600 "
2:abc是根据你的linux系统的用户名定的,我的系统用户名就是abc
[abc@bogon Desktop]$ vi /etc/sysconfig/iptables
增加两行,整个内容可以直接复制下
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5902 -j ACCEPT
这里5901是你用的端口,如果要增加vnc用户请依次增加
然后重启vnc
[root@bogon Desktop]# service iptables restart
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
Applying iptables firewall rules: [ OK ]
Loading additional iptables modules: ip_conntrack_netbios_n[ OK ]
第三步:然后对root下面的/root/.vnc/xstartup文件进行修改,这里注意,运行vncserver在root用户下(不是root也行,改起来麻烦一点点)
#!/bin/sh
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 1024x768+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session &
全部覆盖下就行
重启下vnc服务:
[root@bogon .vnc]# service vncserver restart
PS:这里差不多就配完了,最后一步配置下开机自动启动
第四步:配置自动启动
[root@bogon .vnc]# chkconfig –-level 12345 vncserver on
[root@bogon .vnc]# chkconfig --list vncserver
vncserver 0:off 1:on 2:on 3:on 4:on 5:on 6:off
OK,就大功搞定了,远程访问失败很有可能是xstartup或者iptables出问题,这两个要按上面设置好就行了。