Build a Media Server - Background

Administer Ubuntu Server Trusty Tahr 14.04LTS using VNC

Once you've installed Ubuntu Server you will need a mechanism to be able to administer it. One way is to Install Putty. Putty gives you a "Command Line" interface and so you'll need to learn a few Linux commands in order to be able to administer your server this way. Some people find this prospect rather too daunting and would rather use a graphical user interface (GUI) instead. As a result many people actually install Ubuntu Desktop instead of installing Ubuntu Server since the desktop version of Ubuntu has the GUI built in. There is a better way however, and that is to install VNC. VNC provides a "virtual desktop" so it is more lightweight than a full blown desktop installation.

NOTE: If you're jumping into this guide here then it's worth mentioning that this guide has been tested on Trusty Tahr 14.04LTS, Quantal Quetzal 12.10, Precise Pangolin 12.04LTS, Lucid Lynx 10.04LTS, Karmic Koala 9.10, 9.04 Jaunty, and 8.10 Intrepid. However, at the time of writing VNC is quite flaky on Trusty Tahr 14.04LTS, Quantal Quetzal 12.10 and Precise Pangolin 12.04LTS (although it is getting better all the time) and so I don't particularly recommend you attempt to install it on these versions of Ubuntu. You might want to head over to the forums for the latest views on VNC on 14.04LTS, 12.04 and 12.10

So to perform the installation of VNC you can either type the following commands from a Putty session or, if you've got a screen and keyboard attached to your server, then you can use the command line itself.

First off you need to type:

sudo apt-get update

You'll be prompted for a password. This is the password you created when you installed Ubuntu. Ubuntu tends to prompt for a password each time you issue a "sudo" command.

TIP: If you're going to be following this guide step by step using Putty then you can save yourself some typing by simply highlighting each command below, right-clicking on it and selecting Copy. Then toggle over to your Putty Session and right-click once more. The command you've just copied from here will be automatically pasted into your Putty Session.

Install the Gnome components

First off we need to install the Gnome components for our virtual desktop. So type the following command (or copy it!):

sudo apt-get install gnome-core gnome-session-fallback

when prompted type Y and then press [Enter]. This will install the gnome desktop components.

Install a Virtual Desktop using VNC

Now we've installed the gnome components for the desktop we need to install VNC to be able to interact with it. So type:

sudo apt-get install vnc4server

when prompted type Y and press [Enter]. This will install VNC Server which is required for running the virtual desktop on the server. Next type:

vncserver

You'll then be prompted to create and verify a new password. Once you've entered it you'll see the following screen:

VNC Created

We now need to kill the session we just created and make a tweak to the startup script for VNCServer to make it work properly. If we don't perform this step then all we will see is a grey cross-hatched screen with an "X" cursor and/or a grey screen with a Terminal Session, depending on the Ubuntu version. Not very useful!
You're probably wondering why we just created a session and then killed it before we'd actually used it? Well, creating the session for the first time automatically generates the file we now need to edit.

So, type the following command to kill the session:

vncserver -kill :1

Now type the following command to open up the file we need to edit:

vim .vnc/xstartup

The modifications we need to make to this file depend on the version of Ubuntu we're using so make sure you follow the correct section:

Ubuntu versions up to and including 9.10 Karmic Koala

Scroll down to the line which currently reads #unset SESSION_MANAGER and press the [Insert] key once (this will switch us into "edit" mode) and then remove the #

Do the same for the line after that. Plus change that line to read as follows:

exec sh /etc/X11/xinit/xinitrc

Note the "sh".

Change the xterm -geometry line as below and once you've made these changes the file should look like this:

#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec sh /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 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

Ubuntu Versions 10.04 Lucid Lynx & Maverick Meerkat 10.10

Change the file as above but note the last two lines are different in these versions of Ubuntu:

#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec sh /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 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &

Ubuntu Versions Trusty Tahr 14.04LTS, Precise Pangolin 12.04LTS and Quantal Quetzal 12.10

Change the file so it looks like this:

#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
gnome-session --session=gnome-classic &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &

So, we've unmasked the unset SESSION_MANAGER line, added the line gnome-session --session=gnome-classic & and masked the last two lines out.

All Versions

When you're done editing the file for your particular version of Ubuntu press the [Esc] key once and type the following:

:wq

This should save the changes and bring you back to the command line. If you make a mistake editing the file then issue :q! instead of :wq to abort your changes.

Next type the following command to create the VNC Session once more:

vncserver -geometry 1280x1024

where 1280x1024 is the resolution of your DESKTOP COMPUTER. It has nothing to do with the resolution of the server itself. This command will create a new VNC session on your server. Note: For versions of Ubuntu prior to Precise Pangolin 12.04LTS add a -depth 24 argument so the command should read vncserver -geometry 1280x1024 -depth 24

Next, download and install TightVNC onto your desktop computer. When you launch it type the "X Desktop name" in the VNCServer box. See the DOS-type screenshot above for the name of your "X Desktop name". So, in my case I'd type MyMediaServer:1 in the VNC Server Listbox. See below.

VNC Startup 

then click Connect, enter the password you created when you typed the vncserver command the first time round and you should then see a screen like this (Note that on Precise Pangolin 12.04LTS and Quantal Quetzal 12.10 the screen is blue and that error message doesn't appear):

VNC First Time

Click the Delete button on the error message which is displayed and you now have a nice shiny desktop view onto your server!

Incase you're wondering how what we've just installed differs to simply installing the full blown Desktop version of Ubuntu try connecting a screen to your server now and you'll see it's still sitting there on a black screen with a flashing cursor waiting for you to type your username in. What we've just installed is just a "virtual desktop" onto your server. Neat eh!

Currently this "virtual desktop" runs in a window on your Windows desktop. If you want to switch to "Full Screen" mode, right-click on the TightVNC icon on the taskbar on your windows desktop and select Full screen from the menu. Click OK on the next message. Now it's as tho you're actually sitting in front of your server. Very cool!

To switch out of Full Screen mode and return to Window mode press Ctrl-Esc on your keyboard to bring back your Windows Desktop taskbar. Then right-click on the TightVNC icon on the taskbar and uncheck the Full Screen option.

I know a lot of people wouldn't bother installing a virtual desktop on their servers (and I've no doubt any Linux veterans reading this will be scoffing that I've done so) but I was a total Linux newbie when I started this project and the thought of administering everything using the command line was simply too daunting a prospect. Even tho I now feel much more comfortable with Ubuntu I still find it really handy to just nip into the Ubuntu desktop and tweak something.

When you reboot the server you'll discover that you are unable to re-launch the VNC session and you'll receive a "Failed to connect to server" error message. This is because the vncserver -geometry 1280x1024 -depth 24 command we typed above is not persistent. To solve this we need to ensure that VNC is run on boot: How to run VNC on startup

The Synaptic Package Manager is not installed by default in Lucid or Karmic

At the time of writing the Synaptic Package Manager does not get installed by default in Lucid or Karmic when you install the core gnome desktop. The Synaptic Package Manager is a great tool which makes adding and removing applications a breeze. So we'll simply install it manually by typing the following two commands in a Terminal/Putty session:

sudo apt-get update

sudo apt-get install synaptic

When you now go into your server desktop via VNC you'll find the Synaptic Package Manager under the System -> Administration menu.

How to prevent Gnome starting on the server on boot

On Ubuntu versions 10.10 (Maverick Meerkat), 11.04 (Natty Narwhal), 11.10 (Oneiric Ocelot) & 12.04 LTS (Precise Pangolin) gnome is automatically started on boot once the above instructions have been followed. So, if you connect a monitor to your server you will see the GUI sitting there waiting for you to log in. You can prevent this happening by carrying out the following tweak:

So, issue the following command to open up the relevant script:

sudo vim /etc/init/gdm.conf

You want to mask out the few lines which start the service ie. start on ((filesystem.... so the first few lines of the script should look like this once you've edited it:

# gdm - GNOME Display Manager
#
# The display manager service manages the X servers running on the
# system, providing login and auto-login services

description "GNOME Display Manager"
author "William Jon McCann <mccann@jhu.edu>"

#start on ((filesystem
# and runlevel [!06]
# and started dbus
# and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
# or stopped udev-fallback-graphics))
# or runlevel PREVLEVEL=S)

stop on runlevel [016]

emits login-session-start

Save your changes then reboot the server and that log-in screen should no longer appear. 

Bookmark and Share      

Still stuck? Now what you were looking for? Then head over to the Discussion Forum!