Linux: Headless Ubuntu with VNC

Linux: Headless Ubuntu with VNC

First a little background a few years ago I decided to take an older PC which I have modified to be used as a network attached storage (NAS) and internal web server. I have configured it in the past as a RAID 1 setup with Windows Small Business Server. Recently I have decided to enter the world of Linux and this box will be the first attempt at making a server. I am definitely a n00b in the world of Linux but eager to learn. For this post I will go over how I configured Ubuntu Linux 9.10 for VNC over SSH while using the GDM for graphically logging in to the server.

Need: Since I am new to Linux and still feel more comfortable with a graphical user interface (GUI) it is preferable to be able to use a GUI to administer the server as I did using Windows and their Remote Desktop Connection (RDC) service. My primary needs are to have a headless server that can be maintained via VNC over a SSL secure connection (headless system is a computer that does not have a keyboard, monitor or mouse).

Current configuration:

  • x86 system with system hard drive and a RAID 1 storage array
  • Running Ubuntu Server 9.10 for 32-bit x86

Software:

After some research on the wonderful resources and forums that the Linux community has, I determined what specific software that will be needed to facilitate this server setup. In order to complete this task the following four packages will be installed:

  • Desktop environment: Ubuntu GNOME
  • SSH Server
  • xinetd
  • VNC Server

To operate Virtual Network Computing (VNCW) you will need to install some type of desktop environment, for the purposes of this example, the standard GNOME interface for Ubuntu if you prefer the KDE or XFCE they are also available for Ubuntu. You can look up their install procedures here:

  • KDE (https://help.ubuntu.com/community/InstallingKDE)
    • Command Line: > sudo apt-get install kubuntu-desktop
  • Xfce (https://help.ubuntu.com/community/InstallingXubuntu)
    • Command Line: > sudo apt-get install xubuntu-desktop

To enable a secure shell connection for the VNC I installed Open SSH Server for secure port forwarding.

Installation of xinetd will allow for your VNC services to start on startup of your server, proper configuration of VNC for xinetd will be explained later in this tutorial. For more basic description of xinetd: xinetdW

Finally installation of the VNC Server, for the purposes of this demo we will be installing vnc4server.

How to install the necessary software:

Via the command line:

> sudo apt-get update # Update software packages to the most current available in their repositories (this will insure you will have the most up to date software packages from the approved repositories, this does not guarantee that you will have the newest version just the newest approved in their perspective repository.

> sudo apt-get upgrade # Upgrade current software to the newest from the updated repositories

> sudo apt-get install ubuntu-desktop # Install the Desktop Environment

> sudo apt-get install openssh-server # Install openSSH Server

> sudo apt-get install xinetd # Install xinetd

> sudo apt-get install vnc4server # Install VNC Server

> sudo shutdown -r now # Shutdown and restart your system, the system should boot to the GUI

Upon reboot, you can access the command line for further configuration that is outlined below by going to: Applications > Accessories > Terminal

Configure the VNC Server:

First we will run VNC and will set your VNC password, at the command line:

> vnc4server

The output will list your server name and display number “:#”, please note what number is after the colon, this will be used to shutdown the newly opened VNC session before we configure the VNC startup, now we will shutdown VNC server, at the command line:

> vnc4server -kill :#

Just in case we may need the default file we will backup the file .vnc/startup, at the command line:

> cd ~.vnc/ # Go to the correct directory

> sudo cp startup startup.original # Copy startup as startup.original

Now we will edit the file .vnc/startup

Change the file to look like the following, use your preferred text editor (gedit, vi, etc.), via the command line:

> sudo gedit startup # Open Gedit to edit the file .vnc/startup

#!/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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &

#twm &

We uncommented the previous file to allow execution of the X11 file xinitrc, and commented out some of the configuration that we will not need, now we will need to make this file executable, at the command line:

> sudo chmod 755 /etc/X11/xinit/xinitrc

References:

Configuring xinetd:

Create a file called Xvnc in /etc/xinetd.d/Xvnc this file will be initialized to start your VNC service on startup of your computer, at the command line:

> sudo gedit /etc/xinetd.d/Xvnc

Insert the following text in the file, remember to insert the correct number for the display number (#), usually the default ports for VNC start at 5900, where the port corresponds to the display number, i.e. display :0 > 5900, display :1 > 5901, etc:

service Xvnc

{

type = UNLISTED

disable = no

socket_type = stream

protocol = tcp

wait = yes

user = root

server = /usr/bin/Xvnc

server_args = -inetd :1 -query localhost -geometry 1024×768 -depth 16 -once -fp /usr/share/fonts/X11/misc -DisconnectClients=0 -NeverShared passwordFile=/root/.vncpasswd -extension XFIXES

port = 590#

}

Update, Note: Depending on your setup, the ‘server_args’ statement may need to be changed for the passwordFile location, on my setup the root file is located at /root/.vncpasswd, Derek thankfully pointed out that it also could also be located at /root/.vnc/passwd.  So please verify where your password file is located and update the Xvnc file accordingly.

We will need to restart xinetd, at the command line:

> sudo /etc/init.d/xinetd restart

GDM and XDMCP:

Next we will configure GDM and XDMCP in Ubuntu 9.10 (Thanks to Mark for figuring this out, http://www.peppertop.com/blog/?p=690)

For Ubuntu 9.10 it appears that there has been significant changes to GDM and XDMCP server.

Copy the sample configuration file, at the command line:

> sudo cp /usr/share/doc/gdm/examples/custom.conf /etc/gdm/

Edit the file and enable the XDMCP, this will allow a login screen for your VNC desktop environment, at the command line:

> sudo gedit /etc/gdm/custom.conf

Find the “[xdmcp]” heading and add “Enable=true” below.

Sample file:

# GDM configuration storage

[xdmcp]

Enable=true

[chooser]

[security]

[debug]

Save and close Gedit

For improved security we will disable how the Ubuntu 9.10 uses the newer GDM because by default they list the users at the login screen, to disable this at the command line:

> sudo -u gdm gconftool-2 -t bool -s /apps/gdm/simple-greeter/disable_user_list true

Reference: http://ubuntuforums.org/showthread.php?t=1344205

Configuring X11 to Operate Without a Monitor:

We will need to configure X11 to operate without a monitor, otherwise after you configure your server and disconnect the monitor the VNC will not function properly due to missing hardware.

Create a file called /etc/X11/xorg.conf and paste the following, at the command line:

> sudo gedit /etc/X11/xorg.conf

Insert the following text in the file:

Section “Device”

Identifier “VNC Device”

Driver “vesa”

EndSection

Section “Screen”

Identifier “VNC Screen”

Device “VNC Device”

Monitor “VNC Monitor”

SubSection “Display”

Modes “1280×1024″

EndSubSection

EndSection

Section “Monitor”

Identifier “VNC Monitor”

HorizSync 30-70

VertRefresh 50-75

EndSection

Reference: http://ubuntuforums.org/showthread.php?t=1297815

Hopefully with a configured xinetd, VNC, XDMCP and installed SSH you can restart your machine and try to VNC into your machine.

VNC Clients:

Mac: Jolly Fast VNC, this VNC viewer allows for SSH configuration

Windows: Putty, this VNC viewer allows for SSH configuration

Linux: Vinagre

Ubuntu and other Linux distributions usually have a VNC viewer installed, for this example we will use the preinstalled Remote Desktop Viewer on Ubuntu.  We will create a shell script to both create a SSH connection to your headless server and open the VNC viewer for you to select the server and login.

Example script for using SSH and the built in Remote Desktop Viewer/VNC client on Ubuntu, at the command line:

> sudo gedit /home/username/Desktop/VNCtoServer.sh # Create a new file for the shell script on your Desktop

Insert the following text in the file:

#! /bin/bash

# Open Vinagre VNC Viewer and Open SSH Tunnel to Server for VNC

vinagre & ssh -L 590#:localhost:590# username@servername.local cat – &

exit 0

Save file and close Gedit

> sudo chmod 775 /home/username/Desktop/VNCtoServer.sh        # This will make the shell script file executable

You can now run this script every time you want to VNC into your server.

Linux: TightVNC

To install, at the command line:

> sudo apt-get install xtightvncviewer # Install tightvnc client

For convenience I created a launcher for TightVNC to load with the SSH client, for the Command Field for the launcher: vncviewer -via username@servername.local localhost:590#

I hope this helps, Enjoy!

About the Author