Remote Desktop to your Linux Azure Virtual Machine

If you’ve ever wished you could get a GUI experience with your Azure Linux VM’s, here’s how you can do it. While I’m not suggesting you should do this for production VM’s that are running server workloads, there are times when it could be useful to get a full GUI with Linux. If you are onboard, here’s what you need to do.

Note: If you want you could just follow the steps for getting VNC installed and be done. However, being able to use an RDP client from any Windows machine without installing anything could be more convenient.

I used CentOS 7.1 from the Azure gallery but other RedHat based Linux distros will probably work (e.g. Oracle Linux)

1) Login to your Linux VM

2) Install the GNOME Desktop using this command:

sudo yum groupinstall "GNOME Desktop" "Graphical Administration Tools".

This will take several minutes

3) Install TigerVNC:

sudo yum install tigervnc-server xorg-x11-fonts-Type1

4) Copy the vncserver.service file:

sudo cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

5) Using something like vi, edit /etc/systemd/system/vncserver@:1.service. Look for the <USER> tags in the file and replace with your Linux username.

# Clean any existing files in /tmp/.X11-unix environment

ExecStartPre=/bin/sh -c ‘/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :’

ExecStart=/sbin/runuser -l <USER> -c “/usr/bin/vncserver %i”

PIDFile=/home/ <USER>/ .vnc/%H%i.pid

ExecStop=/bin/sh -c ‘/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'[Install]

WantedBy=multi-user.target

6) If you are running a firewall, you may need to open the ports we will need:

firewall-cmd --permanent --zone=public --add-port=5901/tcp
firewall-cmd --permanent --zone=public --add-port=3389/tcp
firewall-cmd –reload

7) Install XRDP using these commands:

sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
sudo
rpm -Uvh https://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
sudo yum install xrdp
sudo chcon -t bin_t /usr/sbin/xrdp*
sudo systemctl start xrdp.service
sudo systemctl enable xrdp.service
sudo systemctl start xrdp-sesman.service

8) Start VNCServer
vncserver

You will get prompted to enter a VNC password

9) Verify that VNCSever and XRDP are running with netstat –ant:

image

10) Next add the endpoints for RDP and VNC to your Linux VM. It’s probably a good idea to use ACLs to restrict access from a particular remote subnet (see this: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-set-up-endpoints/). Go to your Linux VM in the Azure Management Portal and click on EndPoints. Add an Endpoint for RDP and VNC on ports 3389 and 5901. I picked a random port for RDP (you could do the same for VNC):

image

image

11) At this point you can test connectivity using a VNC Viewer:

 

image

image

12) Next, try a Remote Desktop Connection:

image 

image

Success!

image

12) (optional) If you don’t need VNC exposed externally, you can delete the Azure endpoint and just use RDP

Comments

  • Anonymous
    November 21, 2015
    The comment has been removed

  • Anonymous
    December 02, 2015
    Thanks Mitesh! This article might help you: askubuntu.com/.../how-do-i-start-vnc-server-on-boot. The first answer in that thread should be the one. Let me know how it goes.

  • Anonymous
    March 14, 2016
    Very clear instructions, thanks for the info. However, I'm still having trouble with my VM created with the Resource Manager deployment model. The instructions above talk about adding an endpoint, but since I'm using the Resource Manager deployment model, there's no settings or menu items where I can create one. Instead I added inbound rules to my network security group to allow traffic to ports used by xrdp and vncserver. Rdp and VNC viewer both timeout when I attempt to connect.Additionally, I used the sudo netstat -ant command to confirm that both ports (for xrdp and vncserver) are both in the "LISTEN" state. What am I missing here?Thanks for your time.