How to run desktop applications in Azure X11 Linux virtual machines


How to run desktop applications in Azure X11 Linux virtual machines

A step-by-step walkthrough

By Ross Sponholtz from the Azure Customer Advisory Team (AzureCAT)

This article is also available as a Whitepaper PDF download on Azure.com:

Overview

To use GUI applications on Azure Linux virtual machines, our customers have found it very useful to tunnel X11 traffic over SSH and display it on their workstations. Although you can run X11 remotely over the Internet, we find it works better to use a remote desktop client to connect to an Azure virtual machine running Windows Server, where you install an X Window Server. Then from a Linux virtual machine, you can connect to the Windows virtual machine as your display console. With this setup, you can easily run emacs, system management tools, and other graphical applications on Linux.

This article shows you exactly how to use Azure portal to create a Windows Server virtual machine on the same virtual network as a Linux virtual machine that you also create. We install VcXsrv Windows X server, but you can also use other X11 server applications, such as XMing or MobaXterm if you prefer. For the Azure Virtual Machines documentation on this topic, see Install and configure Remote Desktop to connect to a Linux VM in Azure.

We also show how to install an SSH client to connect to the Linux machine so you can access it from the Windows machine directly. We use PuTTY but you can use another terminal emulator such as MobaXterm. Finally, we test the setup by installing xterm on the Linux virtual machine.

Figure 1. Windows runs VcXsrv to provide display services to the remote Linux virtual machine running MobaXterm.

Step 1: Create an Azure resource group

This walkthrough assumes that you're starting from scratch, so we create a new, empty Azure resource group named X11-test to hold the virtual machines and virtual network created later. If you already have a resource group and virtual network you want to use, you can skip these steps and go to Step 3: Create a Linux virtual machine.

TIP: In Azure portal, display the resource names beside the icons by clicking Menu () on the top left. Click it again to hide the names.

  1. Sign in to the Azure portal at http://portal.azure.com. The Dashboard appears.


  2. In the upper left, click New, then type resource group in the search box and press Enter.

  3. In the Everything blade under Results, click Resource group, then click Create.
  4. In the Resource group blade, type a name for the resource group such as X11-test. Select the subscription and location you want to use, then click Create.

In this example, the X11-test resource group is created in the East US 2 Azure region.

Step 2: Create an Azure virtual network

This step creates a virtual network and adds it to the new resource group. Later, you connect your virtual machines to this virtual network.

  1. On the Azure portal menu, click Resource groups (  ) then, on the Resource group blade, click X11-test (or the name of the resource group you just created).
  2. On the X11test blade, click + Add
  3. On the Everything blade, click Virtual network if it appears; otherwise, type virtual network in the search box and press Enter. Then under Results, click Virtual network
  4. On the Virtual Network blade on the right, click Create.
  5. Type a name for your virtual network such as X11test-vnet. Verify the resource group name and location, review the default settings for address space and subnet, then click Create

In this example, the X11test-vnet virtual network is created in the X11-test resource group.

Step 3: Create a Linux virtual machine

In this step, we create a virtual machine running Ubuntu Linux in our resource group, but you can choose the Linux distribution you prefer. For authentication we set up a username and password, or you can create an SSH key.

  1. On the Azure portal menu, click Resource groups (  ) then, on the Resource group blade, click X11-test or the name of the resource group you created.
  2. On the X11-test blade, click + Add.
  3. In the search box, type unbuntu and press Enter. In the Results, select the Ubuntu distribution, then click Create
  4. Configure the basic settings. Type a name for your virtual machine and choose the disk type. For Authentication type, click Password, then type the username and password you want to use to log on. Verify the resource group name and location, and then click OK
  5. Choose the virtual machine size you want, and then click Select.
  6. For Settings, make sure the virtual network you created earlier is displayed, then click Public IP address. For test purposes, you don't need an Internet-facing IP, so click None, or use the default Internet-facing address if you like, or create a new configurations to fit your case. 
  7. Click Network Security group and choose None to keep this test configuration simple.
  8. To complete the settings, click OK. After the final validation, click OK.
  9. When the server is created, on the Azure portal menu, click Virtual machines (  ), then select MyLinuxVM or the name of the virtual machine you just created.
  10. On the MyLinuxVM blade, click Network interfaces. Make note of the Private IP Address, which you'll need later when you configure PuTTY. 

Step 4: Create an Azure client virtual machine

To access the other virtual machines in our network, a virtual machine running Windows Server is used. This step creates a virtual machine named TestClient.

  1. On the Azure portal menu, click Resource groups (  ) then, on the Resource group blade, click X11-test or the name of the resource group you just created.
  2. On the X11test blade, click + Add.
  3. In the search box, type windows server and press Enter. Under Results, choose the version of Windows Server you'd like to work with. 
  4. On the Windows Server blade on the right, click Create.
  5. Configure the virtual machine's basic settings. Type the name of your virtual machine such as TestClient and choose a disk type. Type the username and password you want to use later to log on to this VM. Verify the resource group and location, and then choose OK
  6. Choose the virtual machine size you want such as D1_V2, and then click Select.
  7. For Settings, make sure that the virtual network you created earlier is displayed. Review the settings for the default Public IP address that will enable this VM to connect to the others. To complete the settings, click OK
  8. After the final validation, review the summary, then click OK to create the Windows Server virtual machine. This process typically takes 3 to 5 minutes.

Now the virtual network is set up, so it's time to create the virtual machines.

Step 5: Install VcXsrv and PuTTY on TestClient

The next step is to log on to TestClient, the client virtual machine running Windows Server, and install the X11 server and the SSH client.

  1. On the Azure portal menu, click Resource groups (), then, on the Resource group blade, click TestClient or the name of the client virtual machine you created in Step 1. 
  2. On the TestClient blade, click Connect
  3. When prompted, click Open to open the Remote Desktop Protocol file (.rdp file). You will get a warning that the .rdp is from an unknown publisher. This is normal. In the Remote Desktop window, click Connect to continue.
  4. When prompted for your credentials, enter the username and password you created for TestClient, then click OK. A warning message about authenticating the remote computer appears; click Yes to continue.
  5. When the remote connection is established, open a browser on TestClient.
  6. To install PuTTY, go to https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html. Select the 64-bit installer and follow the installation instructions.
  7. To install VcXsrv, go to https://sourceforge.net/projects/vcxsrv/. Click Download and follow the prompts.
  8. Keep this session open and continue with the next step.

Step 6: Connect to your Linux virtual machine and test

To make sure you can connect to your virtual machine running Linux, this step walks you through a remote desktop session from the client virtual machine and the required PuTTY configuration settings.

  1. In your remote desktop session on TestClient, run VcXsrv from the icon in the taskbar or the Windows Start menu.
  2. Start PuTTY. In the PuTTY Configuration dialog box, for Host Name (or IP address), enter the IP address noted in Step 3: Create a Linux virtual machine, step 11. In the Saved Sessions box, enter a session name such as MyLinuxVM.
  3. Under Category, expand Connection > SSH > X11, then check the Enable X11 forwarding box.
  4. Under Category, click Session, and then click Save to save the session settings. 
  5. Click Open, accept the SSH certificate, and enter your logon credentials using the username and password you created for MyLinuxVM.
  6. Keep this session open and continue with the next step.

Step 7: Install X11 applications

Now that the connection to the Linux virtual machine is set up through TestClient, the Windows Server virtual machine, you can install the software you need. For this walk-through, we install xterm, the standard terminal emulator for the X Window System.

  1. In your remote desktop session on MyLinuxVM, install the xterm software package by executing the following, substituting your username for ross:

ross@MyLinuxVM:~$ sudo apt-get install xterm

  1. Accept the installation of the indicated packages.
  2. To run xterm, execute the following, substituting your username for ross:      ross@MyLinuxVM:~$ xtermThe xterm icon now appears on your taskbar. 
  3. Click the xterm icon to open an xterm window. 

That's it! This test shows X11 applications are working.

A final word on X11 and sudo sessions

This walkthrough works fine for the user you log on as, but what if you need to run an X11 application in a sudo session? For example, you may need to log on to a host as a non-root user and then create a sudo session to perform administrative functions. If you do this remotely, multiple credentials may be used. If you simply try sudo xterm, it won't work, because the xterm is running as root, but root doesn’t have the proper X11 authentication to connect to your VcXsrv.

To run an X11-based tool, you need to set the proper X credentials in the sudo session by fixing the xauth profile for root. So copy the following in your root .bash_profile, substituting your logon username for adminuser:

su - adminuser -c 'xauth list' |\

        grep `echo $DISPLAY |\

                cut -d ':' -f 2 |\

                cut -d '.' -f 1 |\

                sed -e s/^/:/`  |\

        xargs -n 3 xauth add

Learn more

For more information, see the following resources:

Comments (0)

Skip to main content