peteris.rocks

Remote Desktop and VNC on Ubuntu Server

How to install Remote Desktop and VNC on Ubuntu Server and connect to it from Windows

Last updated on

Let's suppose that for some reason you need to install a graphical user interface on Linux running Ubuntu Server that you want to connect to using Remote Desktop from a Windows machine. Here is how to do that.

Install the following packages:

sudo apt-get install -y ubuntu-desktop gnome-session-fallback tightvncserver xrdp

ubuntu-desktop and gnome-session-fallback will install a desktop environment, tightvncserver will install a VNC server and xrdp will install an RDP server that you can connect to with Remote Desktop (it uses the RDP protocol).

Now we need to set up it all up.

Configure VNC:

mkdir -p ~/.vnc
echo password | vncpasswd -f > ~/.vnc/passwd
chmod 600 ~/.vnc/passwd

Make sure that the desktop environment is launched when you connect with VNC:

cat > ~/.vnc/xstartup <<EOF
#!/bin/sh
def
export XKL_XMODMAP_DISABLE=1
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal &
EOF
chmod +x ~/.vnc/xstartup

xrdp will actually connect to the VNC server so we need to configure xrdp:

sudo bash -c 'cat > /etc/xrdp/xrdp.ini <<EOF
[globals]
bitmap_cache=yes
bitmap_compression=yes
port=3389
crypt_level=low
channel_code=1
[vnc1]
name=vncserver
lib=libvnc.so
ip=localhost
port=5901
username=
password=password
EOF'

Silence some warnings about non-existing files/folders:

touch ~/.Xauthority
mkdir -p ~/.config

Let's start the VNC server:

vncserver

Now you should be able to connect to your server.

This is what it will look like:

Ubuntu Server with Ubuntu Desktop via Remote Desktop screenshot

If you need to, you can stop the VNC server with:

vncserver -kill :1

XFCE

Ubuntu Desktop requires downloading about 500 MB of packages and an additional 2 GB of disk space. If that's too much, you can install a more lightweight desktop environment called Xfce. It's just 45 MB of packages that use an extra 175 MB of space.

Install it like this:

sudo apt-get install -y xfce4 tightvncserver xrdp

Here's is the startup configuration file:

cat > ~/.vnc/xstartup <<EOF
#!/bin/sh
startxfce4 &
EOF
chmod +x ~/.vnc/xstartup

This is what it looks like:

Ubuntu Server with Xfce via Remote Desktop screenshot

Final remarks

Only use this on a computer on a local network or in Vagrant, or secure the ports 5901 and 3389 in the firewall. By default anyone will be able to connect to the server via Remote Desktop and VNC is password protected with a very weak password.

Tested with Ubuntu Server 14.04 LTS using Vagrant.