Configuring GUI and RDP in an Azure Linux VM

Syed Sohaib Uddin
4 min readMay 11, 2020

Microsoft Azure provides VM images in the Linux OS as well. Linux has always been operated via terminal or shell. It is a descendant of UNIX operating systems that were developed in the 1970s. Computers back then were large systems owned by organizations. The entire infrastructure was in a secure room and accessed via punch cards(input) and printers(output). The terminal would have been the tty(teletype). Only later did we have a keyboard and a terminal. This style of communication with the machine became a convention and is followed until now. Even with GUIs around, Linux continues to be operated from the shell.

Linux VMs are also operated from the command line of your desktop via an SSH (secure shell) connection. They do not have a desktop environment or GUI installed by default. For Windows users migrating to Linux, a desktop environment would be more convenient to operate. Hence, various desktop environments can be set up on a Linux VM.

In this blog, we will work on installing the lightweight xfce4 desktop environment on a Linux Ubuntu VM.

Getting started

  1. To start working, we will need a Linux VM. Setup a Linux VM by following the steps here.
  2. Connect to your VM by typing the following in your PowerShell.
ssh -i <private key path> <VMUsername>@<public ip address>

The VMusername and public IP address can be found in the overview tab of your VM page. The private key path is under the SSH tab in the connect option.

3. Enter your VMpassword and connect.

4. We now install xfce4 using apt .

sudo apt-get update
sudo apt-get -y install xfce4

sudo : It stands for ‘super user do’. Typically used to grant superuser access for operations. It is analogous to ‘run as administrator’ in Windows.

apt-get : It is used for retrieving packages on Linux distributions.

Note : apt is a package index that holds records of packages in your system and used to installing, updating, removing and managing them.

apt update : It is used to update the apt package index.

install xfce4 : Installs xfce4 environment. Xfce is a lightweight desktop environment for UNIX-like operating systems. It aims to be fast and low on system resources, while still being visually appealing and user friendly.

5. With the desktop environment ready, we now have a GUI. In order to access it, we must connect the VM via RDP. Hence, an RDP server must be configured on the VM.

6. We now install xrdp RDP server onto the VM. Execute the following in your shell.

sudo apt-get -y install xrdp
sudo systemctl enable xrdp

xrdp is an open-source RDP server available on Linux distributions and works well with xfce.

7. At this point, we must introduce xrdp server to xfce4 desktop environment. This is basically telling the server what desktop environment to use on connection establishment.

echo xfce4-session >~/.xsession

8. Restart the xrdp server to update the changes.

sudo service xrdp restart

9. With you already having your VM password, everything is ready except for routing incoming traffic. Remote desktop protocol requires TCP on port 3389 to reach the VM for connection establishment. With no RDP connection earlier, network security group rules were not configured to receive inbound traffic. Hence, VM network rules have to be modified. We now need to access Azur via cmd to reconfigure our VM.

10. Open cmd on your desktop and login to Azure:

az login

Note: Make sure AzureCLI is downloaded to your machine in order to run Azure commands.

On successful login, type the following:

az vm open-port --resource-group <ResourceGroupName> --name <VM name> --port 3389

Put your Resource group name, VM name and run. On successful execution, you must see an additional port configured on your VM.

11. Connect to your VM via RDP from your desktop. Enter your public IP address.

Enter your VM username and password to log in.

Enjoy using a GUI in your Linux VM.

Summary

We have learned that -

  • Linux VMs are generally accessed via shell.
  • A desktop environment like xrce4 can be installed into a Linux machine.
  • In order to access a Linux VM via RDP, an RDP server must be installed.
  • A network port must be opened for TCP connection via RDP to the VM.

Hope this was useful.

Further reading:

Linux VMs in azure — https://docs.microsoft.com/en-us/azure/virtual-machines/linux/

--

--