Thursday, March 03, 2011

Configuring vnc on CentOS

It was a pain, as most of the latest linux distros come with out-of-box vnc support,
but I finally found a good reference on CentOS site:


To make your centOS server vnc ready, you just need to :
  1. Create your VNC users.
  2. Set your users' VNC passwords.
  3. Edit the server configuration.
  4. Customize xstartup scripts.
$ su -
$ useradd vncuser

$ cd .vnc
$ vncpasswd

$ vi /etc/sysconfig/vncservers
VNCSERVERS="1:vncuser" VNCSERVERARGS[1]="-geometry 800x600"
$/sbin/service vncserver start
$/sbin/service vncserver stop

$ cd .vnc
$ vi xstartup

Edit xstartup. The original should look like:

#!/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 & 

Add the line indicated below to assure that an xterm is always present, and uncomment the two lines as directed if you wish to run the user's normal desktop window manager in the VNC. Note that in the likely reduced resolution and color depth of a VNC window the full desktop will be rather cramped and a look bit odd. If you do not uncomment the two lines you will get a gray speckled background to the VNC window.

#!/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 &

Start the vncserver as root.
$ /sbin/service vncserver start

and that's it ! Use vncviewer to connect ot it
$ vncviewer host_ip:1

My Blog List