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.
- 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.
- 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.
- 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.
- On the Settings pane, you can leave all the default values, and click OK.
- 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:
- 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>
- 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.
- 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.
- 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/
- 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
- Next, you need to start xrdp running on the VM. This can be done with the following command:
/etc/init.d/xrdp start
- 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.
- On the Network security group blade, click on the Inbound security rules link.
- Click the +Add button then fill in the following details for a new Inbound security rule to open port 3389, then click OK.
- Source: Any
- Source port ranges: *
- Destination: Any
- Destination port ranges: 3389
- Protocol: TCP
- 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!
Nice guide. Thank you sharing this.
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.
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. 🙂
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
Are you sure there weren’t any errors when you ran the necessary commands to set things up?
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
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!
Thanks for the tips. So far I haven’t used Azure yet for setting up Linux VMs; just Virtualbox. Great article.
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.
Did you follow the steps outlined in the article? Perhaps retrace and double check.
Yes, I follow to step by step but not working
Something may have gone wrong. Did you try it again with a new VM?
the instructions were clear and succinct, worked like a charm!
Superb Chris… You saved my day… I just did what was told here and walla… my linux VM was up and running in Azure…
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..
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.
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
I tried this, xrdp got running nice and easy but connecting just gave issues after the login screen, from both windows and macOS.
The Azure data science ubuntu box comes with x2Go server installed and running out of the box.
Just download the x2go client and you get up and running instantly.
I have to say that x2go experience is far nicer way to RDP into linux!
Awesome post Chris. I was well into it following the instructions when I saw your “username” in the settings and realized this was yours! On the “One Year Anniversary” of the post, I thought I’d give you an update or two. 🙂 As you are aware, Azure changes regularly, so now you can just select the Ports 22 and 3389 during the build in the allow ports section, no need to build or modify any NSG. You can, if you miss that during the build and only select 22, but this is at least capable of being done in one step during the deploy if you would like.
Hope things are going well my friend!
Thanks! And, thanks for pointing this out. Everything is great, I hope you are well too. 🙂
Thanks for it.
Keyboard does not work!
Hi,
Thanks for this article. I am using an iPad with an external keyboard.
The VM starts fine, but once the Desktop loads, no keyworks, only mouse works.
You’re having an iPad related issue. Keyboard input to the VM works just as expected to the Linux VM over RDP as it would with Windows.