VNCServer在Linux下设置

来源:互联网 发布:淘宝拍立得功能 编辑:程序博客网 时间:2024/06/06 02:59
1.检查vnc客户端和服务器是否已经安装:
[root@centos ~]$ rpm -q  vnc-server 

package vnc-server  is not installed  说明没有安装

运行yum install vnc-server进行安装

vnc-server-4.0-8.1  说明安装已经安装了 只是没开启服务而已
2. 将用户名称加入到配置文件: 
(注:这里的“用户名”是指linux系统用户的名称) 
[root@centos ~]# vi /etc/sysconfig/vncservers 

# Uncomment the line below to start a VNC server on display :1 
# as my 'myusername' (adjust this to your own). You will also 
# need to set a VNC password; run 'man vncpasswd' to see how 
# to do that. 

# DO NOT RUN THIS SERVICE if your local area network is 
# untrusted! For a secure way of using VNC, see 
# .
#VNCSERVERS="1:myusername"//这段为原有内容

注:这里用到vi命令,按下Insert键就可以输入以下内容,输入完成后,按ESC键跳到命令模式然后,输入:w 保存文件:
# VNCSERVERS="1:root2:admin" # use the method for more user 
VNCSERVERS="1:root 2:admin "     //这句就是添加用户 可以添加多人 
#VNCSERVERARGS[1]="-geometry800x600" 
VNCSERVERARGS[1]="-geometry 1024x768"    //这句应该是分辨率 可以不要
3. 设置用户root的密码 
[root@centos ~]$ vncpasswd 
Password: 
Verify:
4. 启动VNC服务               
 [root@centos ~]# /sbin/service vncserver start 
Starting VNC server: 1:root [ OK ]
5. 修改VNCSERVER的窗口治理器 
[root@centos ~]#vi ~/.vnc/xstartup
#!/bin/sh  
# Uncomment thefollowing two lines for normal desktop: 
# unsetSESSION_MANAGER 
# exec/etc/X11/xinit/xinitrc 
 
[ -x /etc/vnc/xstartup ]&& exec /etc/vnc/xstartup 
[ -r $HOME/.Xresources ]&& xrdb $HOME/.Xresources 
xsetroot -solidgrey 
vncconfig -iconic& 
xterm -geometry80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & 
#twm&          
   //这里加个# ,用于注释,加粗的为原有内容
gnome-session&   //加上这行 
#startkde #kdedesktop #如果是用kde去掉这行前面的注释号即可
 6. 重启vncserver 
[root@centos ~]#/sbin/service vncserver restart
Shutting down VNC server: 1:root[ OK ] 
Starting VNC server: 1:root [ OK ]
7.查看VNC端口   
[root@ centos ~]#netstat -ntlp 
8.把防火墙端口打开      
[root@centos ~]#vi /etc/sysconfig/iptables 
找到以下的语句:  
-A RH-Firewall-l-INPUT-j INPUT-j REJECT - reject-withicmp-host-prohibited  
在此语句前面加上下面的内容:  

-A Rh-Firewall-l-INPUT-m state -state NEW-mtcp-p tcp-dport 5901 -j ACCEPT //5901为查看到的VNC的端口号

VNC的默认端口是5900,而远程桌面连接端口则是5900+n(n是vncserver命令指定的)。如果使用“vncserver :1”命令启动VNC Server,那么下面的端口应该是5901。

9.重启iptables服务    
[root@centos ~]#service iptables restart 
10. Windows登陆到VNC Server 
打开windows下的VNC客户端
在服务器栏输入 
192.168.159.129:1 (这里,我的VNC服务器在192.168.159.129上,用的是Display1(对应root帐号)) 
加密:让服务器选择(默认)