Skip to content

June 24, 2009

2

Setting up headless Ubuntu with XFCE and VNC (Slicehost)

I recently have to setup a headless Ubuntu box (on slicehost) with GUI support. After search the web I couldn’t find a clean solution. So here it is, hopefully people don’t have to spend as much time as I did.

This solution is based on Ubuntu install on slicehost.

STEP 1 (SERVER):
First, setup your machine’s basic security by following this:

http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-1

STEP 2 (SERVER):
Next, ssh to your box with your admin user (not root) and install xfce and vnc:
>sudo aptitude install vnc4server
>sudo aptitude install xfce4

STEP 3 (SERVER):
Now we want to run a quick test on the vncserver:
>vnc4server -geometry 1024×768

It should ask for a password, type in something you can remember, this will be your vnc password.
You should see something like:

You will require a password to access your desktops.

Password:
Verify:
xauth:  creating new authority file /home/adminA/.Xauthority

New 'HostA:1 (adminA)' desktop is HostA:1

Creating default startup script /home/adminA/.vnc/xstartup
Starting applications specified in /home/adminA/.vnc/xstartup
Log file is /home/adminA/.vnc/HostA:a.log

All seems fine. Now kill vnc:
>vnc4server -kill :1

STEP 4 (SERVER):
Setup vnc to start xfce:
>vi ~/.vnc/xtartup (or use your favorite editor)

The file should look lie:

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

Now change the last couple of lines to:

xsetroot -solid grey
vncconfig -iconic &
# xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
# twm &
startxfce4

Server setup is now DONE!

STEP 5 (Client):
If you have followed the setup in Step 1, your iptables should be configured to open only http, https and ssh. Instead of opening port for VNC, we will do ssh tunneling. (Slightly more hassle but much more secure):

On your client machine (Windows, Mac, etc), with your favorite ssh client:

(assume you setup your ssh port in step 1 to 4567, hostA is the server name, adminA is the username)

>ssh -p 4567 -L 5902:localhost:5901 hostA -l adminA

On Putty (PC),

Goto the Tunnels setting inside Connection->ssh
Source Port : 5902
Destination: localhost:5901
Hit Add. The following should show up in the Forwarded ports list:
“L5901 localhost:5901″

Once logged in the server, start vnc:

>vnc4server -geometry 1024×768

Then leave the session running. You are almost done.

STEP 6 (Client):
Now just start your favortie VNC client and connect to: localhost:5902

Note because we are using SSH tunnel, VNC to connect to localhost instead of your server. Port should be 5902 and not 5901. SSH will do the rest.

XFCE should now show up.

STEP 7 (Client)
Yes, there is a Step 7. That’s the clean up. We don’t want VNC to be running all the time so when you are done, before killing the ssh session, kill VNC:

>vnc4server -kill :1

From now on all you need to do is to repeat Step 5-7.

Enjoy!

Read more from Software Development

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments