Vnc installation on centos ubuntu and debian

Installing the Components

Our VPS images are intended to be very minimal to allow the most user customization, so you must install the full group packages for Xwindows and Gnome (the default window manager for most operating systems). For CentOS:

 

yum groupinstall "X Window System" "GNOME Desktop Environment" vncserver

For Ubuntu (as root):

apt-get install ubuntu-desktop gdm vnc4server

For Debian (as root):

apt-get install xorg gdm gnome vnc4server

You will also need a VNC viewer for your PC. If you are on Microsoft Windows, you can try one of the free VNC viewers such as RealVNC Free Version. For Mac, we reccomend the open source project Chicken of the VNC.

Running VNC Server

Out of the box, the X server should come configured properly. We will however need to configure the VNC server to start automatically as well as start a new X server session when it is started as well.

First, we’ll make sure VNC is working OK:

vncserver :1

This will start the VNC server for the first time, create some configuration files, and start the VNC server listening on port 5091 (make sure to open this port in your firewall if necessary). You can now use your VNC viewer to connect to your server to make sure it is working properly. You can use the syntax hostname.domain.com:1 to connect to the server.

Running X Server

Once you have logged in for the first time, you will notice VNC only launches an xterm window with a very basic interface by default. We want to change its configuration to start a Gnome graphical environment when launched so we have a nice GUI to work with.

What we need to do is first stop the running VNC server:

vncserver -kill :1

Next we need to edit /root/.vnc/xstartup (or /home/user if you’re running the server as a regular user) and modify the final line in the file, which should read twm & to the following (note the last line):

#!/bin/bash
# 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" &
unset SESSION_MANAGER
gnome-session &

If this file doesn’t exist, create it, and make sure it is executable (chmod 0777).

Once done, we can restart our VNC server:

vncserver :1

Now you can log in as you did before, however this time you will be presented with a Gnome Desktop environment!

Starting on Boot

If you would like your VNC server to start with the system boot, we will need to modify the init startup scripts. For CentOS:

chkconfig vncserver --levels 2345 on

For Debian/Ubuntu, the VNC server should be automatically configured to start on boot. If not, you may need to update the rc scripts:

update-rc.d vnc4server default