Vnc4server on Ubuntu 10.04

After several hours wasted trying to setup an automated vnc server on Ubuntu 10.04 I’ve finally got it working.  Here’s how:

-install vnc4server via package manager.  “sudo apt-get install vnc4server” should also work

execute “vnc4server” as my local user.  This prompts me to set a password and ~/.vnc directory for the first time.

modify ~/.vnc/xstartup to start gnome, and not startup x-window-manager.  My xstartup file now looks like this:

#!/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 &
x-terminal-emulator -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
#x-window-manager &
gnome-session &

#!/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/.Xresourcesxsetroot -solid greyvncconfig -iconic &x-terminal-emulator -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &#x-window-manager &gnome-session &

Next, I created a /etc/init.d/vnc4server file.  It look like this:

#!/bin/sh -e

### BEGIN INIT INFO
# Provides:          vncserver
# Required-Start:    networking
# Default-Start:     S
# Default-Stop:      0 6
### END INIT INFO

PATH=”$PATH:/usr/X11R6/bin/”

# The Username:Group that will run VNC
export USER=”chris” #<– my local user

# The display that VNC will use
DISPLAY=”1″

# Color depth (between 8 and 32)
DEPTH=”16″

# The Desktop geometry to use.
#GEOMETRY=”<WIDTH>x<HEIGHT>”
#GEOMETRY=”800×600″
GEOMETRY=”1024×768″
#GEOMETRY=”1280×1024″

# The name that the VNC Desktop will have.
NAME=”filebox-vnc-server”

OPTIONS=”-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}”
. /lib/lsb/init-functions

case “$1” in

start)
log_action_begin_msg “Starting vncserver for user ‘${USER}’ on localhost:${DISPLAY}”
su ${USER} -c “/usr/bin/vnc4server ${OPTIONS}”
;;

stop)
log_action_begin_msg “Stoping vncserver for user ‘${USER}’ on localhost:${DISPLAY}”
su ${USER} -c “/usr/bin/vnc4server -kill :${DISPLAY}”
;;

restart)
$0 stop
$0 start
;;

esac

exit 0

Finally, I installed and ran “sysv-rc-conf” to make the vnc4server process start when the machine boots (runlevel 2,3,4,5)

after rebooting the machine you should be able to access it via vnc.  Try it locally with a vnc viewer by using host: localhost:1