Monday, July 1, 2019

Creating a Ubuntu Desktop instance on Azure

We have multiple Linux offerings on Azure for the server but none for the desktop. How can we build one hassle-free?

Azure offers a variety of Linux servers including RedHat RHEL, CentOS, Debian and Ubuntu. But no desktop. As developers, it would be nice to have access to a development VM on the cloud with a GUI running software like Visual Studio Code, Firefox and Chrome/Chromium.

On this post, let's see how to install the necessary software to transform an Ubuntu server into a functional Ubuntu desktop.


The requirements for a desktop VM are pretty much a Desktop Manager and a browser. All the rest can be done via the command line with tmux, git, vim, ranger and bash. Because it's a VM, let's make it lightweight and install LXDE on it.

Note that you may also want to install Visual Studio Code which can be easily done by following this tutorial.

Creating the Instance

The base image for our desktop will be Ubuntu Server 18.04 LTS. As this is a server image, it doesn't contain a GUI. We will install it ourselves as long as a browser and a tool to connect remotely via RDP. By default we can connect to it via SSH using our WSL or Putty.

In Azure, click "Create a Resource" then select Ubuntu Server 18.04 LTS:

Configuring VM Details

Now let's configure the VM. Here we will set the username, password, VM name, resource group, region, etc that are adequate to you. For example, my configuration is show below:

Setting up Disks

The next step is disk setup. I selected Premium SSD with 10GB as seen below:

Setting up the Network

For the network interface, I created a new VNet/Subnet and asked for a new IP to be created by Azure. Note that the IP will only be available to us after creation. For me, as this is just a demo VM, I chose to create everything as a new resource.

I also want to select inbound ports that should be open (we will need them accessible later). Remember as this is important: select SSH (22) and RDP (3389):

Review and Create

Review and if everything's correct, click on Create to proceed:

After a couple of minutes the instance should be created and running.

Connecting to our Instance

Once our instance is deployed, let's connect to it. Depending on how you configured during creation, it can be accessed via username/password or via SSH. You should use Azure's overview window to get important information as IP address and username.

To access it within Azure, click the Connect tab from which you should have an output similar to:

Because I configured ssh and uploaded my ssh key, I simply have to open my WSL and enter the following command:
# connect to my remote server using ssh
ssh bruno@<my-ip>
This is the output of my first connection to that VM:

Note: if you chose to provide an username/password during creation, you're still good to connect via SSH. The only difference is that you'll have to provide your password upon connection.

Diagnosing Connection Issues

If for some reason you get ssh: connect to host port 22: Resource temporarily unavailable it's because the port 22 (SSH) is not open for connection externally. And that's a good thing! It pretty much tells us that our connection is being blocked by a firewall. By default in Azure, VMs are wrapped into a Network Service Group (NSG) which is an extra layer of protection to our cloud artifacts. It basically provides full control over traffic that ingresses or egresses a virtual machine in a VNet.

In order to open that port we click on the Networking tab to change our inbound rules. Here's what I currently have:

To add a new one, we click the Add inbound port rule button and enter the rule as below:

Security Warning

Please note that it's recommended that you only expose ports that are essentially necessay to to security threats. In our example, we should only expose ports 22 (SSH) and 3389 (RDP). It's also recommended to configure your NSG to restrict access to your IP only. Once that's done, try to connect again with:
# connect to my remote server using ssh
ssh bruno@<my-ip>

Installing the Required Tools

With the VM up and running and with ssh access to it, it's time to install the required tools to make our server more user friendly. Remember, we'll have to install a desktop manager, some CLI tools and Firefox.

Updating the system

The first thing to do should be updating the system and the list of packages available to your Ubuntu instance with:
# Updating the package Sources
sudo apt-get update && sudo apt-get upgrade

Install CLI tools

The next step is to install useful CLI tools to work (some of them are already pre-installed with the Azure/Ubuntu image):
# install basic terminal tools
sudo apt install tmux git ranger vim

Install LXDE

Now, let's install our desktop (LXDE). The good news is that Canonical, the good folks behind Ubuntu, already provide a metapackage called lubuntu-desktop that contains not only LXDE but firefox and other very useful GNOME tools. We install it using the following command:
sudo apt-get install lubuntu-desktop -y
Please note that this installation take a while as ~2GB of files have to be downloaded and installed on your server.

Installing XRDP and starting the Service

The last and final step is to install the xRDP package. As previously mentioned, this tool is required to connect to our instance using RDP. This installation downloads ~8Mb and runs very quickly after the above commands. Type the following on the shell:
# install xrdp
sudo apt-get install xrdp -y
Next step is to start the xrdp service so we can connect to it via RDP.
# start the xrdp service
sudo systemctl start xrdp

Connecting via RDP

All should be good to go now so let's try to connect to our machine. Simply enter the IP address on the RDP information and hit connect. On mine, I got the prompt:

Note that if when creating your VM on Azure you selected SSH, you have to setup a new password for your user. This is done with:
# setting up a new password for our user
sudo passwd bruno


If you enter your password correctly, you should login to your LXDE session. This is my awesome LXDE session running on Azure. By clicking on the blue icon above you'll have access to all the software included with the metapackage:

Persisting Changes

What happens after a reboot? Will the VM still run xrdp? No. Unless we make the service permanent. If that's what you want, do that by running the below command on the terminal:
# permanently enable the xrdp service during boot
sudo systemctl enable xrdp

Final Thoughts

The cloud is an awesome environment to test new things out. On this example I used Azure but you could reproduce pretty much everything here on your cloud provider of choice.

It's also important to remember that two of the most fundamental aspects of a Linux system is customazation and extensibility. So, installing/changing a GUI, trying out different softwares, adding/removing repos, etc should be simple on the cloud as is on a local VM. And that shouldn't prevent us from being creative and using our imagination.

I encourage you to play with Azure or your preferred cloud provider and experiment not only with a Ubuntu Linux VM but with other services and tools. It's all a few clicks away!


Ubuntu Metapackages 
Network Service Groups (NSG)
Azure - Available disk types
Azure - VMs Types and Sizes

See Also

Why I use Fedora
How I fell in love with i3
Windows Subsystem for Linux, the best way to learn Linux on WindowsWhy I use Fedora
How I fell in love with i3
.NET Core and .NET merging as .NET 5.0
Copying data between Azure databases in 3 easy steps

For other Linux posts on this blog, please click here