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”
ExecStop=/bin/sh -c ‘/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'[Install]
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
rpm -Uvh
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
You will get prompted to enter a VNC password
9) Verify that VNCSever and XRDP are running with netstat –ant:
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: 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):
11) At this point you can test connectivity using a VNC Viewer:
12) Next, try a Remote Desktop Connection:
12) (optional) If you don’t need VNC exposed externally, you can delete the Azure endpoint and just use RDP

Leave a Reply

Your email address will not be published. Required fields are marked *

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