Manage Ubuntu Server using Remote Desktop Connection

Anyone who has ever worked on a Windows platform will be familiar with Microsoft Remote Desktop Connection (RDC). RDC is used to connect to or manage another computer running some version of Windows over a network connection. With cloud platforms such as Azure and AWS, we can easily spin-off virtual machines based on Windows or Linux within seconds. Wouldn’t it be great if we can connect to or even mange Linux Servers hosted in cloud using the same Remote Desktop Connection?

I have used my Azure subscription to spin-off an Ubuntu Server. This server runs in the US-East region inside a specific resource group lab-ue-rg.

In case of Linux Servers, Azure, by default, allows inbound traffic to port 22 which is the port used by SSH protocol.

To manage this Ubuntu Server using Remote Desktop Connection, we need to install xrdp package. Start by connecting to the remote Ubuntu Server using SSH protocol from the terminal window. Type the remote password when prompted. In Azure, credentials are specified when creating a new virtual machine.


ssh [remote_user_name]@[remote_host]

Once connected to the Ubuntu Server, first step would be to update the packages.


sudo apt-get update

Since this is a new virtual machine, let’s also set a password for the root account.


sudo passwd root

We can now log-in using the root account credentials we just set.


su -

To install xrdp, type the following command:


sudo apt-get install xrdp

This will install all the required packages on the Server. Once the installation is complete, we need to inform Azure to allow inbound traffic on port 3389 which is the default port used by Remote Desktop Connection.

In the Azure portal, create a new inbound rule for RDP. Note that the rule will take immediate effect.

Inbound rules should now list RDP as well, indicating that inbound traffic is allowed on port 3389.

We can now use the Remote Desktop Connection to connect to our Ubuntu Server hosted on Azure. The remote server should prompt a dialog to enter credentials to connect to the xrdp session.

Once login is successful, the terminal window on the remote server will be displayed. You have now successfully connected to the Ubuntu Server using Remote Desktop Connection.

This is good but let’s take it a bit further. Those not familiar with Linux environment will struggle using the terminal window. Let us install a desktop environment on our server. We want to make sure we install a light-weight desktop environment that will not consume server resources.

xfce is a very light desktop environment and we can install the same on the server. We will also install vnc4server that will allow us to interact with the desktop environment on a remote server using keyboard and mouse.


apt-get install xfce4
apt-get install vnc4server

Once the vncserver is installed, we need to set the screen resolution we want. When prompted, type a password.


vnc4server -geometry 1024x768

By default, vncserver is already running. We need to kill the service so that we can configure the vncserver to use xfce desktop environment.


vnc4server -kill :1

In case you are wondering, :1 is the screen number. Each user on a Linux machine can have their own screen display.

Since we want to setup the screen display for the normal user account (not the root account), we need to exit from the root account and run the vncserver service under the normal user account. Exit from the root account and start the vncserver service under the normal user account. When prompted, specify a password.


vnc4server

When the vncserver service starts, a default startup script will be created under ~./.vnc/xstartup. We need to modify the startup file to instruct vncserver to use xfce desktop environment. So, one more time, we need to kill the vncserver service and modify the startup file using some editor.


vnc4server -kill :1
vi ~/.vnc/xstartup

In the startup file, comment all lines that starts with x-terminal and x-window. Add startxfce4 to the bottom of the file. This will start the xfce desktop environment. Save the file and quit the editor. Now we can start the vncserver service by specifying our desired screen resolution.


vnc4server -geometry 1024x768

Using Remote Desktop Connection, let’s connect to our Ubuntu Server hosted on Azure one more time. We should see the familiar prompt to enter the credentials to connect to the remote session.

Once valid credentials are provided, this time we will be welcomed with xfce desktop environment.