Some time back I wrote about doing Visual Studio development with an Azure Virtual Machine (VM). In that article, I showed how you can setup a Windows VM for Development purposes to extend your local development machine with the help of the cloud. In this article, I want to share some tips I’ve found in how to setup a Linux VM in Azure that you can use for similar purposes.

It’s worth noting that the steps to install RDP support outlined below will work with any Ubuntu Server instance; not just one running in Microsoft Azure. ūüôā

Linux Support for Remote Desktop (RDP)

Normally, when you setup a Linux VM (perhaps Ubuntu Server) in Microsoft Azure, you can only connect to and remote into it via SSH. The reason this differs from a Windows VM in Azure; as Linux VMs do not support Remote Desktop (RDP) natively. Essentially this causes you to be required to SSH into Linux VMs, while you remote into Windows VMs over RDP.

If you’re not familiar with Windows Remote Desktop, it’s a technology that lets you remotely connect to a Windows PC or VM from another computer in a manner that enables you to see the screen interface (UI) as if you were sitting directly at that computer.

Traditionally, the only way to remotely connect to a Linux VM is to use SSH (Secure Shell). This is a technology that enables a user to remotely connect to a Linux machine (PC or VM) from another computer using the Shell or command-line interface. Due to the nature of SSH, the Linux machines command-line is only accessible through the SSH connection. You do not get the Desktop-style UI of the Linux machine that you might get if you were to install Ubuntu or some other distribution on a local computer or Virtual Machine (VM).

The xrdp project is an open source project that added Remote Desktop Protocol (RDP) support to Linux machines. By installing xrdp you can add the ability to use Remote Desktop to remote into a Linux VM. This then grants you the ability to connect to the Linux machine with a graphical user interface (UI) similarly to how you would connect to a Windows machine using Remote Desktop.

Setting up a Linux VM in Azure

First, we’ll need to create a Linux VM to use. For this, I’m going to recommend provisioning a Ubuntu Server VM in Microsoft Azure. If you’re unfamiliar with creating a Linux VM in Azure, follow these steps. If you’re already familiar, then feel free to skip down below to the steps to enable RDP support on the Linux VM.

  1. Using the Azure Portal (http://portal.azure.com), click on Create a resource in the left-side navigation, then select the Compute category, then click on Ubuntu Server. At the time of writing this the version listed is Ubuntu Server 16.04 LTS.
  2. Next, fill in some details about your VM, such as the Name, Username, and method of Authentication. To keep things simple, you’ll want to set the Authentication type to¬†Password, then enter a password you’ll use to login with the¬†User name¬†you’ve entered. Also, don’t forget to specify the Resource Group too, before clicking¬†OK.
  3. For the VM Size, I would recommend choosing a size with at least 2 vCPUs, as this will give you better performance for the UI. Although, 1 vCPU would work just fine too, just maybe a little more slowly.
  4. On the Settings pane, you can leave all the default values, and click OK.
  5. Finally, click Create on the Summary pane to create the new Ubuntu Linux VM!

Now that you have an Ubuntu Server Linux VM, you are ready to setup RDP support.

Installing RDP Support on the Linux VM

To install RDP support on your Linux VM, you’ll need to use SSH to perform the install of xrdp, and you’ll also need to make sure there’s a desktop UI installed on the Linux VM so RDP will work once installed. I recommend using lxde as it’s simple and lightweight.

You can follow these steps to install RDP support and lxde on the Linux VM:

  1. Within the Azure Portal, locate the Virtual machine blade for your Linux VM. Then clicking Create button will give you a sample SSH command to use at the Bash Shell. Or, you can also retrieve the Public IP address from the Overview pane to type the command manually, or using a utility like PuTTy to connect.
    The SSH command will have the following syntax:

    ssh <username>@<ip address>
    
  2. When using the SSH command, you’ll need to enter it into a bash shell on your local machine. This could be the “Ubuntu Bash Shell” on Windows 10, or a Terminal window on macOS.
  3. When prompted, enter the Username and Password what was specified for the Admin user when the Ubuntu Linux VM was created previously.
    Also, you’ll likely be prompted with an “Are you sure you want to continue connecting (yes/no)?” message. The reason for this is that your local machine hasn’t seen the key fingerprint from that Linux machine yet. For the sake of the exercise, type¬†yes and press Enter to continue. Once you enter “yes”, you’ll need to enter the SSH command again to initiate the connection.
  4. Next, you’ll need to install a Desktop graphical UI (User Interface) before you’ll be able to setup RDP support. To do this, you can run the following command to install lxde on the Linux VM:
    sudo apt-get install lxde -y

    If you’re interested in using the Ubuntu Desktop UI instead, you can use the great tips from Sorcia25 here:¬†https://sorcia25.wordpress.com/2018/03/02/how-to-setup-an-ubuntu-linux-vm-in-azure-with-remote-desktop-rdp-access-ubuntu-desktop-gui/

  5. Next, you’re ready to install RDP support by installing the xrdp project on the VM. You can do this with the following command:
    sudo apt-get install xrdp -y
  6. Next, you need to start xrdp running on the VM. This can be done with the following command:
    /etc/init.d/xrdp start
  7. Next, before you can Remote Desktop into the Linux VM, you need to be sure to open port 3389 on the Network Security Group (NSG) that is securing access to the VM within Azure. To do this, navigate to the Resource group blade for your VM, then click on the Network Security Group resource.
  8. On the Network security group blade, click on the Inbound security rules link.
  9. Click the +Add button then fill in the following details for a new Inbound security rule to open port 3389, then click OK.
    1. Source: Any
    2. Source port ranges: *
    3. Destination: Any
    4. Destination port ranges: 3389
    5. Protocol: TCP
    6. Action: Allow

With RDP support installed on the Ubuntu Server Linux VM in Azure, and the NSG Firewall is open on Port 3389 to allow RDP connections, you are ready to use a Remote Desktop client to connect.

Connect to Linux VM with Remote Desktop Client

Once RDP support is installed and enabled on a Linux VM, you can now connect to it and remote into the machine using Microsoft Remote Desktop (RDP). You can do this from the Remote Desktop application on Windows, or macOS.

Here’s a screenshot of setting up the connection information using the Microsoft Remote Desktop application on macOS. Note that you need to enter the Public IP Address of the Linux VM in Azure, and the Username and Password that were used to create the VM (or any other username and password that is currently configured on the VM).

And, here’s the final screenshot of what the RDP screen looks like for the Ubuntu Server Linux VM in Azure with both xrdp and lxde installed. This screenshot was taken from macOS using Remote Desktop to connect to the Linux VM running in Azure, and the screen shows the Firefox web browser running on the Linux VM along with a Terminal window running the Bash shell.

I hope this tip and guide help you with your Linux needs in the Microsoft Azure cloud!

GET MORE STUFF LIKE THIS

Subscribe to the Build Azure Weekly newsletter to receive similar updates about Microsoft Azure and related topics!


We respect your privacy and take protecting it seriously. We do not sell our email list, and you can unsubscribe at any time.

Posted by Chris Pietschmann

Chris is a Microsoft MVP and has nearly 20 years of experience building enterprise systems both in the cloud and on-premises. He is also a Certified Microsoft Azure Solutions Architect (both MCSD and MCSE), a Microsoft Certified Trainer, and self proclaimed Cloud Advocate. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.

18 Comments

  1. Nice guide. Thank you sharing this.

    Reply

  2. […] days ago¬†Chris Pietschmann wrote about How to Setup an Ubuntu Linux VM in Azure with Remote Desktop (RDP) Access¬†(great job¬†certainly), and in a little ping pong messages I ask about how to enable another […]

    Reply

  3. Nice one Chris.
    Looks like this doesn’t work with Remote Desktop Connection Manager and RDP session should be launched separately to be able to see something else than a blank screen.

    Reply

    1. Chris Pietschmann March 7, 2018 at 4:53 pm

      I’ve connected to a Linux VM with xrdp like the article describes from both Windows and Linux desktop computers. I’m not sure what the issue is that you’re seeing. If you find more information about this, please share, and maybe we can figure it out. ūüôā

      Reply

      1. I also followed all the steps, and in the end when I connect to the remote VM all I see is a black blank screen

      2. Chris Pietschmann April 22, 2018 at 9:20 pm

        Are you sure there weren’t any errors when you ran the necessary commands to set things up?

  4. Nice, thanks for the write up.
    To use xfce4 instead of lxde I found I also had create an .xsession file in the user home directory:
    echo xfce4-session >~/.xsession

    Reply

  5. Melwin Dmello May 18, 2018 at 7:32 am

    Thanks for this post. It helped me!! I just faced an issue with xrdp running on 3389.

    (Writing this, in case it helps someone else)

    I setup an Ubuntu 18.04 LTS on Azure. For some reason enabling port 3389 using Network Security group didn’t work for me.
    Therefore, I used the Endpoints options to expose port 3389.

    Also, after executing /etc/init.d/xrdp start, check the status using sudo service xrdp status
    In my case, there were some issues :
    May 18 10:55:22 ubuntuMachine1 xrdp[36242]: (36242)(140648438613824)[ERROR] Cannot read private key file /etc/xrdp/key.pem: Permission denied

    I resolved this by:
    sudo chmod 777 /etc/xrdp/key.pem
    sudo service xrdp stop
    sudo service xrdp start
    (Probably, running xrdp with sudo would have worked!!)

    Checking status again, showed:
    May 18 10:58:38 ubuntuMachine1 xrdp[36655]: (36655)(140482085226304)[INFO ] listening to port 3389 on 0.0.0.0

    Once, xrdp was listening on 3389. I could RDC from my windows machine and I connect my Ubuntu VM ‘s deskop!!!
    Thanks again Chris!! Cheers!

    Reply

  6. Thanks for the tips. So far I haven’t used Azure yet for setting up Linux VMs; just Virtualbox. Great article.

    Reply

  7. umutalparslan June 26, 2018 at 3:59 am

    Hello,

    I setup the Linux VM but not working. Please help me. My Inbound Port Rules -> https://i.hizliresim.com/mo1jGy.png and RDP Error -> https://i.hizliresim.com/ED5nV9.png VM work right now but RDP not connecting.

    Reply

    1. Chris Pietschmann June 30, 2018 at 1:59 pm

      Did you follow the steps outlined in the article? Perhaps retrace and double check.

      Reply

      1. umutalparslan June 30, 2018 at 6:13 pm

        Yes, I follow to step by step but not working

      2. Chris Pietschmann June 30, 2018 at 7:37 pm

        Something may have gone wrong. Did you try it again with a new VM?

  8. the instructions were clear and succinct, worked like a charm!

    Reply

  9. Superb Chris… You saved my day… I just did what was told here and walla… my linux VM was up and running in Azure…

    Reply

  10. I followed the instructions after having deployed a fresh Microsoft Ubuntu VM (linux-data-science-vm-ubu).

    I can get through the login screen okay and can see on log as last message that ‘connection complete, connected ok’, but then I get gray screen, apparently waiting for some content to appear, I see a cursor as X..

    But then the window dies and disappears in 1-2 seconds..Both using Windows 7 and Windows 10 as client machines…

    Strange..

    Reply

    1. Chris Pietschmann October 16, 2018 at 10:58 am

      The Ubuntu machine may not be setup correctly. Also, I’ve seen this type of issue if the Desktop UI, if not using lxde, may not be compatible with xrdp.

      Reply

      1. Right.. I am sure you are right.. ūüėČ

        Fortunately I was able to skip debugging phase as I found out that the Azure system was pre-configured with X2go so I got this running simply installing and configuring the client on my Windows machines

        https://docs.microsoft.com/en-us/azure/machine-learning/data-science-virtual-machine/dsvm-ubuntu-intro

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.