Running Ubuntu Desktop on an AWS EC2 instance

Key Value
Summary Learn how to connect and run Ubuntu desktop on AWS EC2 Instance. Access GUI to manage your machine more easily.
Categories server
Difficulty 2
Author Simran Singh invincible.simran@gmail.com

Overview

Duration: 0:01

This tutorial will guide you through the setup of running ubuntu desktop on an AWS EC2 instance using TightVNC on a system running Ubuntu 16.04+.

What you’ll need :

  • Access to an AWS EC2 instance using commandline - This tutorial assumes that you’re logged into the machine using SSH
  • A machine running ubuntu 16.04+
  • Remmina Remote Desktop Client (Pre-installed on 16.04+)

Originally authored by Simran Singh.

Setting up TightVNC on AWS

Duration: 0:02

Let’s install Ubuntu Desktop and TightVNC on your EC2 instance. After logging in to your EC2 instance using the terminal, enter the following commands to install the tools that will be required to run Ubuntu desktop :

ⓘ While installing VNC Server you’ll be required to setup a password for the server. So remember this since it will be needed later to connect to our VNC server.

 sudo apt update
 sudo apt install ubuntu-desktop
 sudo apt install tightvncserver
 sudo apt install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal

After completion, your machine is ready with GUI support but needs some configuration to be done.

Configuring the VNC server

Duration: 0:05

In your terminal type the following command to launch VNC server to create an initial configuration file:

 vncserver :1

Open the configuration file in vim:

 vim ~/.vnc/xstartup

Press the ‘i’ key on your keyboard to get into the insert mode which will allow you to enter text into the file. Edit the file to look like so :

#!/bin/sh

export XKL_XMODMAP_DISABLE=1
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

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

vncconfig -iconic &
gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal &

After you’re done, enter ‘Ctrl + :’ and type ‘wq’ to save and quit the file.

Great! We’re almost done with the configuration. Now, let’s restart the VNC server by killing it first and then starting it up.

To kill the vnc server and start it again, type the following command:

vncserver -kill :1

vncserver :1

Congratulations, you’re done with the configuration for Ubuntu Desktop.

AWS Configuration

Duration: 0:02

We need to make sure that the AWS instance has inbound rules setup to allow connection using VNC. So, head over to your AWS EC2 console and modify the inbound-rules. Add the entry : Custom TCP Rule | TCP | 5901 | Custom | 0.0.0.0/0 | VNC Connect

Save this entry. Done!

Connecting to Ubuntu Desktop

Duration: 0:02

Launch Remmina Remote Desktop Client. Then, 1. Choose the connection type as ‘VNC’

  1. Enter your EC2 url along with the port number as 1. For eg. : My EC2 instance URL and the port number as 1 will be
 ec2-54-172-197-171.compute-1.amazonaws.com:1

3. Enter the password you provided during the installation of the VNC Server. 4. Connect!

Congratulations, you’ve successfully configured your EC2 instance to run Ubuntu Desktop GUI Support.

Hope you liked the tutorial.

Finding help

Duration: 0:02

The Ubuntu community, for both desktop and server, is one of the friendliest and most well populated you can find. That means if you get stuck, someone has most likely already been there and solved the same problem.

Try asking for help in one of the following:

Alternatively, if you need commercial support for your server deployments, take a look at Ubuntu Advantage.

Please consider adding an alternative way described below.

https://www.brianlinkletter.com/how-to-run-gui-applications-xfce-on-an-amazon-aws-cloud-server-instance/

One correction in the doc is to use gvncviewer instead of xvncviewer. Otherwise it works good.

In the “AWS Configuration” step the instructions say to “Add the entry : Custom TCP Rule | TCP | 5901 | Custom | 0.0.0.0/0 | VNC Connect”
However the inbound rules in the screenshot have 5 different rules. It’s unclear to me whether all 5 are necessary, just 1 is necessary, or just the 2 port=5901 rules are necessary. Please clarify if possible.

It’s not clear if the HTTP inbound rules are needed

Please update for Ubuntu 20.04 LTS in AWS EC2. Doesn’t work entirely. Posting a screenshot of what actually comes through.

This is the xstartup configuration that worked for me on 20.04.

#!/bin/sh
xsetroot -solid grey
export XKL_XMODMAP_DISABLE=1
export XDG_CURRENT_DESKTOP="GNOME-Flashback:Unity"
export XDG_MENU_PREFIX="gnome-flashback-"
unset DBUS_SESSION_BUS_ADDRESS
gnome-session --session=gnome-flashback-metacity --disable-acceleration-check &
1 Like

Totally works, thank you! Not sure if the graphics can be fixed… attached.

1 Like

Also, noticed this peculiarity… the dashboard or favorites bar on the left is missing…
2021-08-16_14-14-49

The color is configured on your VNC client. I have the same configuration posted and I got full color :slight_smile:

Your solution even works with hippo. I’m still confused about the activities bar, searching…

1 Like

Looks great! As you mention, it is indeed confusing. The trick here is that VNC is building another desktop session and is using gnome-flashback-metacity as a windows manager, which, doesn’t have the dash menu (left side icons panel).

There must be a way to add it, though, but I haven’t tried yet

Cheers!

Actually tried running these commands on Ubuntu 16.04 in AWS EC2. Doesn’t work there either. This entire tutorial needs to be fixed, https://ubuntu.com/tutorials/ubuntu-desktop-aws#1-overview. This doesn’t work on any version of Ubuntu I’ve tried. The “Activity” bar on the left doesn’t show up at all, and as carlos-bravo indicated, requires different settings for the xstartup file. Please fix the tutorial/documentation. Thanks.

These instructions don’t work on newer versions of Ubuntu that package applications as Snaps.

You need to add:

export XAUTHORITY=$HOME/.Xauthority

… to xstartup in order to prevent “client is not authorized to connect to server” errors from all Snap applications (including Firefox).

That is outdated. We have a newer tutorial here: Launch Ubuntu Desktop Mantic Minotaur on EC2 - #3 by carlos-bravo