VNC is used to display an X windows session running on another computer. Unlike a remote X connection, the xserver is running on the remote computer, not on your local workstation. Your workstation ( Linux or Windows ) is only displaying a copy of the display ( real or virtual ) that is running on the remote machine.
There are several ways to configure the vnc server. This HOWTO shows you how to configure VNC using the 'vncserver' service as supplied by CentOS.
1. Installing the required packages
The server package is called 'vnc-server'. Run the command rpm -q vnc-server.
The result will be either package vnc-server is not installed or something like vnc-server-4.0-11.el4.
If the server is not installed, install it with the command:
yum install vnc-server
The client program is 'vnc'. You can use the command yum install vnc to install the client if rpm -q vnc shows that it is not already installed.
Make sure to install a window manager in order to get a normal GUI desktop. You can use the command yum groupinstall "GNOME Desktop Environment" to install the Gnome Desktop and requirements, for example. Other popular desktop environments are "KDE" and "XFCE-4.4". XFCE is more light-weight than Gnome or KDE and available from the "extras" repository.
If you are running CentOS 5, yum groupinstall "GNOME Desktop Environment" may complain about a missing libgaim.so.0. This is a known bug. Please see CentOS-5 FAQ for details.
2. Configuring un-encrypted VNC
We will be setting up VNC for 3 users. These will be 'larry', 'moe', and 'curly'.
You will perform the following steps to configure your VNC server:
1.Create your VNC users.
2.Set your users' VNC passwords.
3.Edit the server configuration.
4.Create xstartup scripts.
5.Test each VNC user.
2.1. Create your VNC users
As root:
# useradd larry
# useradd moe
# useradd curly
# passwd larry
# passwd moe
# passwd curly
2.2. Set your users' VNC passwords
Login to each user, and run vncpasswd. This will create a .vnc directory.
[~]$ cd .vnc
[.vnc]$ ls
passwd
2.3. Edit the server configuration
Edit /etc/sysconfig/vncservers, and add the following to the end of the file.
VNCSERVERS="1:larry 2:moe 3:curly"
VNCSERVERARGS[1]="-geometry 640x480"
VNCSERVERARGS[2]="-geometry 640x480"
VNCSERVERARGS[1]="-geometry 800x600"
Larry will have a 640 by 480 screen, as will moe. Curly will have an 800 by 600 screen.
#-----------------------------------------------------------------
vim /etc/sysconfig/vncservers
找到以VNCSERVERS开头被注释掉的行,将注释去掉,加入所有在系统重新引导时自动启动的VNC会话,确保每个用户和对应的数字X匹配.
VNCSERVERS="1:wenz 2:xuanw 3:mirrorw 4:kevinl 5:ericc 6:danield 7:berniey 8:zacharyz"
VNCSERVERARGS[1]="-geometry 800x600"
VNCSERVERARGS[2]="-geometry 800x600"
VNCSERVERARGS[3]="-geometry 800x600"
VNCSERVERARGS[4]="-geometry 800x600"
VNCSERVERARGS[5]="-geometry 800x600"
VNCSERVERARGS[6]="-geometry 800x600"
VNCSERVERARGS[7]="-geometry 800x600"
VNCSERVERARGS[8]="-geometry 800x600"
#-----------------------------------------------------------------
2.4. Create xstartup scripts
We will create the xstartup scripts by starting and stopping the vncserver as root.
# service vncserver start
# service vncserver stop
Login to each user and edit the xstartup script. To use Larry as an example, first login as larry.
[~]$ cd .vnc
[.vnc] ls
mymachine.localnet:1.log passwd xstartup
Edit xstartup. Add the line indicated here, and uncomment the two lines as directed.
#!/bin/sh (-)
# Add the following line to ensure you always have an xterm available.
( while true ; do xterm ; done ) &
# 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 &
2.5. Test each VNC user
2.5.1. Testing with a java enabled browser
Let us assume that mymachine has an IP address of 192.168.0.10. The URL to connect to each of the users will be:
Larry is
Moe is
Curly is
Connect to . A java applet window will pop-up showing a conection to your machine at port 1. Click the [ok] button. Enter larry's VNC password, and a 640x480 window should open using larry's default window manager.
2.5.2. Testing with a vnc client
For Larry: vncviewer 192.168.0.10:1
For Moe: vncviewer 192.168.0.10:2
For Curly: vncviewer 192.168.0.10:3
To test larry using vncviewer, vncviewer 192.168.0.10:1. Enter Larry's VNC password, and a 640x480 window sholud open using Larry's default window manager.
2.5.3. Starting vncserver at boot
To start vncserver at boot, enter the command
chkconfig vncserver on.
3. VNC encrypted through an ssh tunnel
You will be connecting through an ssh tunnel. You will need to be able to ssh to a user on the machine. For this example, the user on the vncserver machine is Larry.
1.Edit /etc/sysconfig/vncservers, and add the option -localhost. VNCSERVERS="1:larry 2:moe 3:curly"
VNCSERVERARGS[1]="-geometry 640x480 -localhost"
VNCSERVERARGS[2]="-geometry 640x480 -localhost"
VNCSERVERARGS[1]="-geometry 800x600 -localhost"
2.service vncserver restart
3.Go to another machine with vncserver and test the VNC. a.vncviewer -via localhost:1
b.vncviewer -via localhost:2
c.vncviewer -via curly@192.168.0.10 localhost:3
4. Recovery from a logout
If you logout of your desktop manager, it is gone!
We added a line to xstartup to give us an xterm where we can restart our window manager. For gnome, enter gnome-session.
For kde, enter startkde.
5. VNC-Sever setup with no hassles with vnc-ltsp-config
To allow all users login screen access via a vnc-client to the system, you can use vnc-ltsp-config and xinetd. When a vnc-client connects to one of the configured ports, the user will be given a default standard login screen. The sessions will *not* be persistent. When a user logs out, the session is gone.
The rpm package vnc-ltsp-config is easily installed via the EPEL repository noted near the bottom of
Note: There are no major dependencies for the package so the vnc-ltsp-config*.rpm could easily be downloaded and installed without the need for enabling the EPEL repository.
Install, as root via:
# yum install xinetd vnc-ltsp-config
# chkconfig xinetd on
# chkconfig vncts on
# service xinetd restart
This will add the ability to get the following default vnc-client based session connecitons:
resolution
color-depth
port
1024x768
16
5900/tcp
800x600
16
5901/tcp
640x480
16
5902/tcp
1024x768
8
5903/tcp
800x600
8
5904/tcp
640x480
8
5905/tcp
A major advantage of using the vnc-ltsp-config setup is the reduction of system resource utilization compared to the standard "per-user setup". No user processes will be started or memory consumed until a user actually logs into the system. Also, no pre-thought for user setup is needed (eg skip all of the manual individual user setup for vnc-server). The downside to the vnc-ltsp-config setup is that *any* user with the ability to login will likely have the ability to log into the system via a vnc-client with full gui unless steps are taken to limit that type of access. Also, there is no session persistance! Once the vnc-client closes, the vnc-ltsp-config session will terminate (by default) and all running processes will be killed.
6. VNC-Server for an already logged in GUI console session - 2 options
Often you will need remote access to an already logged in GUI session on a "real" console. Or you will need to help another user remotely with an GUI or visual issue. You will need either "vnc-server" or "x11vnc". The vnc-server option will be a module added to X11 for "allways on" vnc support, while x11vnc will allow for adhoc vnc support.
vnc-server install will require no third party repos or source building.
x11vnc is a way to view remotely and interact with real X displays (i.e. a display corresponding to a physical monitor, keyboard, and mouse) with any VNC viewer. In this way it plays the role for Unix/X11 that WinVNC plays for Windows.
6.1. x11vnc adhoc option
Karl Runge has generously provide a exceptional amount of information at for x11vnc. There is info on securing the connection and also an "Enhanced TightVNC Viewer (ssvnc)". To make it easy, follow these steps:
1. Download the latest rpm install from to the host you want the vnc-client to connect to:
wget
2. Install, as root, via the yum or rpm programs on the host you want the vnc-client to connect to:
yum install x11vnc-0.9.3-1.el5.rf.i386.rpm
3. Start the x11vnc process on the host you want the vnc-client to connect to. Please take a long look at the possible options from the x11vnc website. A very simple/insecure example for a trusted network setup (local network or VPN) is to have the user with the GUI console issue the command:
[user@helpme_host ~$] x11vnc -nopw -display :0.0
Then connect (without password) via a vnc-client to the IP/hostname and port noted by the x11vnc command. By default, x11vnc will allow connections from all interfaces. Host based firewall settings may need to be modified.
You can combine this with ssh tunneling:
ssh -C -t -L 5900:localhost:5900 [remote ip] 'x11vnc -usepw -localhost -display :0'
Note that the -C flag is for compression, so may not be required
6.2. vnc-server X11 "always on" option
1. On the the system you want to run vnc-server, install vnc-server as noted above.
2. Edit /etc/X11/xorg.conf, as root, and add/create a 'Module' Section and add 'Load "vnc"':
Section "Module"
Load "vnc"
EndSection
3. For standard vnc authentication, edit /etc/X11/xorg.conf, as root, and add to the 'Screen' Section:
Option "SecurityTypes" "VncAuth"
Option "UserPasswdVerifier" "VncAuth"
Option "PasswordFile" "/root/.vnc/passwd"
4. As root, run 'vncpasswd" to create the password noted above.
5. Restart X11 (++ will work if on the console already)
6. You should be able to connect with a vncviewer client as normal.
7. To trouble shoot, check for errors in the /var/log/Xorg.0.log or verify that iptables or selinux is not interfering with remote connections. Additional information is at