Linux 下配置VNCserver

Linux VNCserver的配置
1.查看VNC是否已经安装:
$ rpm -q vnc vnc-server

vnc是客户端,vnc-server是服务器端

2.把用户名加入到配置文件中:


CODE:[root@localhost ~]#  vi /etc/sysconfig/vncservers

# The VNCSERVERS variable is a list of display:user pairs.
#
# 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
# URL:http://www.uk.research.att.com/vnc/sshvnc.html
                                                                                              
# VNCSERVERS="1:myusername"
VNCSERVERS="1:root"
3.用vncpasswd创建一个vnc的口令

注意这将同时在你的home目录下,创建一个隐藏的目录.vnc,其中有一个文件passwd保存着你的vnc口令.


CODE:
[root@localhost ~]# vncpasswd
Password:
Verify:
[root@localhost ~]# ls -d .vnc
.vnc
[root@localhost ~]# ls .vnc
passwd
4.启动vnc服务.


CODE:[root@localhost ~]# service vncserver restart
Shutting down VNC server: 1:root                           [ OK ]
Starting VNC server: 1:root perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "zh_EN.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log

                                                           [ OK ]

察看一下.vnc这个目录的内容,应该类似于下面的东西.


CODE:[root@localhost ~]# cd .vnc
[root@localhost .vnc]# ls
localhost.localdomain:1.log localhost.localdomain:2.log passwd
localhost.localdomain:1.pid localhost.localdomain:2.pid xstartup
[root@localhost .vnc]#

编辑这个名为xstartup的脚本,注意到下面红色的部分的注释
将这两行标记成红色的内容前面的注释符号去掉,否则你将只能得到一个什么都没有的灰屏。#!/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 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

因为我们已经修改了启动脚本,现在来重新启动vncserver.


CODE:[root@localhost .vnc]# service vncserver restart
Shutting down VNC server: 1:root                           [ OK ]
Starting VNC server: 1:root perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "zh_EN.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log

                                                           [ OK ]
[root@localhost .vnc]#
5.防火墙端口设置
在使用防火墙的情况下来连接到一个远程系统,需要打开端口5901.
加入以下红色的部分,然后重启iptables服务。

[root@localhost ~]# vi /etc/sysconfig/iptables

# Firewall configuration written by redhat-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0]
:FORWARD ACCEPT [0]
:OUTPUT ACCEPT [0]
:RH-Firewall-1-INPUT - [0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT

[root@localhost ~]# sudo /sbin/service iptables restart
Flushing firewall rules:                                   [   OK   ]
Setting chains to policy ACCEPT: filter                    [   OK   ]
Unloading iptables modules:                                [   OK   ]
Applying iptables firewall rules:                          [   OK   ]
[root@localhost ~]#
================================
其他:
================================

1. 让vncserver接受两个不同的用户:


CODE:VNCSERVERS="1:root 2:yanyp"
当然你要为两个用户分别运行vncpasswd来设置口令. 并且在你的防火墙修改中,你应该明白VNC使用端口5901给连接1用,如果象上面一样要支持两个用户,应同时打开5901和5902.

2. 如果安装了用客户端vncviewer可以使用 vncviewer命令来远程连接vncserver

[root@localhost ~]$ vncviewer localhost(或者用IP地址):1

输入你的vnc口令,就可以了

你可能感兴趣的:(linux,职场,vncserver,休闲)