Remote Desktop Ubuntu 14.04: How To Use an Ubuntu UI Remotely

Overview

INAP offers access to virtual or bare metal servers in many ways. For customers who wish an Ubuntu desktop user interface (UI) as opposed to using solely a command line interface (CLI) tools or secondary UI such as cPanel or Plesk, this article will show how to set up that remote desktop session using standard open source tools and minimal CLI expertise.

This would be valuable for:
• Clients using OS level hosting for their first time
• Clients with small requirements
• Clients that don’t have a large staff but are somewhat familiar with Linux UI

Software Requirements

These will be installed during the process below:

Server:

  • Xfce4
    • A free and open-source desktop environment for Unix operating systems like Linux, Ubuntu, etc.
  • Xfce4-goodies
    • Additional software and artwork related to Xfce but not part of the official release
  • Tightvncserver
    • A free, remote control software package which allows the user to see the remote desktop of the machine and control it with a local system mouse and keyboard

Client:

  • puTTy
    • A free, open-source SSH and telnet client which will allow access via the CLI to a server.
  • realVNC, tigerVNC, or tightVNC
    • A series of free remote access software tools.

Installing GNOME and VNC

  • Log in to your Linux server as root user via SSH
  • ~sudo apt-get update

u-14-img 1

  • ~sudo apt-get install xfce4 xfce4-goodies tightvncserver

u-14-img2

When asked whether you want to continue, select “Y”

u-14-img3

To complete the VNC server’s initial configuration, use the vncserver command to set up a secure password:

  • ~ vncserver

After you set up your access password, you will be asked if you would like to enter a view-only password. Users who log in with the view-only password will not be able to control the VNC instance with their mouse or keyboard. This is a helpful option if you want to demonstrate something to other people using your VNC server.

u-14-img4

u-14-img5

  • Set passwordvnc

This allows a password to be set used accessing VNC desktops

u-14-img6

Configuring VNC for Remote Access to the Desktop

  • Editing the startup file

The VNC server needs to know what commands to perform when it starts up. These commands are located in a configuration file called xstartup. The VNC server has an xstartup file preloaded already, but some different commands are required for the XFCE desktop.

When VNC is first set up, it launches a default server instance on port 5901. This port is called a display port, and is referred to by VNC as :1. VNC can launch multiple instances on other display ports, like :2, :3, etc. When working with VNC servers, remember that :X is a display port that refers to 5900+X.

As the way the VNC server is configured will be altered, the VNC server instance currently running on port 5901 will need to be stopped.
~ vncserver –kill :1

u-14-img7
Before configuring the new xstartup file, back up the original in case it is needed later.
~ mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
u-14-img8
Now a new xstartup file can be created with with nano (text editor) and insert the following commands to start VNC Server upon server startup:
~nano ~/.vnc/xstartup
u-14-img9
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &

u-14-img10

Ctrl+X to save it
Grant this file executable privileges:
~ sudo chmod +x ~/.vnc/xstartup

u-14-img11

A restart of the vncserver service may be required for host connection.
~vncserver

u-14-img12

New ‘X’ desktop is ubuntu1404:1, based on the name of the server in question being ubuntu1404.

  • Editing the VNC server configuration file

To easily control the new VNC server, it should be set it up as an Ubuntu service. This will allow us to start, stop, and restart the VNC server as needed.
First, open a new service file in /etc/init.d with nano and insert the following text into the file:
~sudo nano /etc/init.d/vncserver
u-14-img13
#!/bin/bash
unset VNCSERVERARGS
VNCSERVERS=””
[ -f /etc/vncserver/vncservers.conf ] && . /etc/vncserver/vncservers.conf
prog=$”VNC server”
start() {
. /lib/lsb/init-functions
REQ_USER=$2
echo -n $”Starting $prog: “
ulimit -S -c 0 >/dev/null 2>&1
RETVAL=0
for display in ${VNCSERVERS}
do
export USER=”${display##*:}”
if test -z “${REQ_USER}” -o “${REQ_USER}” == ${USER} ; then
echo -n “${display} “
unset BASH_ENV ENV
DISP=”${display%%:*}”
export VNCUSERARGS=”${VNCSERVERARGS[${DISP}]}”
su ${USER} -c “cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}”
fi
done
}
stop() {
. /lib/lsb/init-functions
REQ_USER=$2
echo -n $”Shutting down VNCServer: “
for display in ${VNCSERVERS}
do
export USER=”${display##*:}”
if test -z “${REQ_USER}” -o “${REQ_USER}” == ${USER} ; then
echo -n “${display} “
unset BASH_ENV ENV
export USER=”${display##*:}”
su ${USER} -c “vncserver -kill :${display%%:*}” >/dev/null 2>&1
fi
done
echo -e “\n”
echo “VNCServer Stopped”
}
case “$1” in
start)
start $@
;;
stop)
stop $@
;;
restart|reload)
stop $@
sleep 3
start $@
;;
condrestart)
if [ -f /var/lock/subsys/vncserver ]; then
stop $@
sleep 3
start $@
fi
;;
status)
status Xvnc
;;
*)
echo $”Usage: $0 {start|stop|restart|condrestart|status}”
exit 1
esac
u-14-img14
Ctrl+X to save it
Grant this file executable privileges:
~chmod +x /etc/init.d/vncserver
u-14-img15
Next make the configuration file for the server as follows and insert the something resembling the following text:
~mkdir -p /etc/vncserver
u-14-img16
~nano /etc/vncserver/vncservers.conf
u-14-img17
VNCSERVERS=”1:root”
VNCSERVERARGS[1]=”-geometry 1024×768″
Note root was used for this example, but it is strongly suggested to create a VNC user and not use root for production

img18
Here the port comes to be 5901 & 1024×768 resolution for the VNC client, you can choose a resolution of your own choice.
Ctrl+X to save it
Now to add the file to the boot startups and reboot the machine:
~update-rc.d vncserver defaults 99

img19
~reboot

img20
Now restart of the vncserver service may be required for host connection.
~vncserver

img21
Output is below:
New ‘X’ desktop is ubuntu1404:2
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/ubuntu1404:2.log

Configuring A Tunnel to the Linux Desktop

  • Open PuTTy
  • In the Category section, select Connection > SSH > Tunnels

22

  • Type and enter the following, and then click Add:
    • Source port — Type 580, plus the port you specified in the VNC configuration file. Because we used port 2 in that example, here we would enter 5801.
    • Destination — Type 580, plus the port you specified in the VNC configuration file. Because we used port 2 in that example, here we would enter 5801.
  • Type and enter the following, and then click Add:
    • Source port — Type 590, plus the port you specified in the VNC configuration file. Because we used port 2 in that example, here we would enter 5901.
    • Destination — Type 590, plus the port you specified in the VNC configuration file. Since we used port 2 in that example, here we would enter 5901.

23

  • In the Category section, navigate to Session.
  • In the Saved Sessions field, type VNC Tunnel, and then click Save

24
Make sure that the server has port 5902 to allow VNC access.  Adjust this within Horizon or via the CLI.

Accessing the Linux Desktop

Each time the Linux remote desktop is accessed, the SSH tunnel configured must be loaded. Then open an Internet browser that has Java applets enabled to log in to VNC.
Access the Linux Desktop with a VNC client. Recommended client options are below.

  • TigerVNC
  • TightVNC
  • RealVNC
  • Open PuTTY, select the saved session, click Load, and then log in to the server. This opens the SSH Tunnel.
  • Open the preferred VNC Client, type hostname:590[n] (where [n] is the port specified in the VNC configuration file, and then press Enter.

25
This opens a secure connection from your Linux server to your desktop and you should see a screen similar to the one below.

26