I’ve worked on and off with Linux for years. All of it using Linux as a web server. Generally I am most comfortable using Windows as my dev environment, although I love Mac too.
Lately I’ve wanted to develop web apps in a Linux environment using Linux-based tools and then deploy those to a Linux server. I haven’t bothered yet to go purchase a bunch of super fast USB 3.0 storage yet so I looked at creating a Linux VM in Azure and using that instead.
Note: I should note that I started this process by searching for existing information on how to do this. However, what I found either didn’t work or forced me to do something I didn’t want (i.e. install Cyg-Win and use X-Windows, or install vncViewer, etc.). A number of blog posts I found missed a couple of key pieces of info that tripped me up as I followed them. The best topic I found on doing this was this one on Ubuntu Tutorials, Remote desktop to Ubuntu 12.04 from Windows 7. I want to make sure I cite this as the source (there is no author unfortunately or I would credit that person out directly) I used that was clearly written and actually worked.
Ok, with that out of the way, let me walk you through the steps I followed to create a desktop Linux environment using a Linux VM in Azure.
Step 1: Provision a Linux VM
Fire up the Azure Management Portal and provision a new Ubuntu VM. Since our purpose here is to enable an interactive remote user login to this VM we we are going to specify a user name and strong password rather than a SSH key.
Note: This is super critical and its where I got tripped up using information I found online. You have to use 12.04 LTS. I tried 14.04 and despite numerous attempts I could not get it to work. (Update: Apparently this works with 15.10 per a comment below)
Step 2: Selecting VM Instance Sizes
While provisioning your VM you will need to select a VM size. You may be tempted to create a small VM because after all it’s not doing much. Don’t do this. I tried this using a small VM and screen refreshes were painfully slow. (Move the mouse and go grab a coffee slow) Medium was better but still unusable as a desktop. You need a VM with lots of CPU power to handle screen draws. I selected a Basic Large because I don’t need load balancing or other features. Yes it costs $300/month but I don’t need to run this 24/7. I have it running at most 30 hours a month so that’s less than $15 a month.
Step 3: Open the Remote Desktop Protocol Port
After the VM has been successfully provisioned you need to open the right port so you can connect to it via RDP. To connect to the VM using RDP, open port 3389. To do that click on Properties for the VM in the Azure Management Portal, select End Points and then you create an end point in the Azure Portal.
Note: you can change the port you use for RDP if you want but you will need to edit the xrdp.ini file in your Linux VM after you install RDP. To do that SSH into the VM and navigate to /etc/xrdp/xrdp.ini and edit the Port number, it’s at the end of the file. Save the file, quit VIM and then reboot the VM to ensure it’s listening on the right port.
Step 4: Connect via SSH
After the VM is ready you need connect to it so you can update apt-get, install a desktop environment and install RDP. In the old days one would use a utility like PuTTY to provide Windows users a UNIX/Linux command shell from which you could connect to remote Linux machines and do stuff. However, if you have Git Bash installed you already have everything you need. Just open Git Bash and type the following:
Tip:There is also another tool that if you aren’t using you should called ConEmu. This is by far the best shell I’ve ever used. It replaces the Windows shell, GitBash, and PowerShell with a single app. Go install it now. I’ll wait.
So next fire up the ConEmu shell and SSH into your new Linux VM.
Step 5: Update apt-get
Once connected you need to update your VM’s package repository to make sure it has the latest references for software packages available and their dependencies. This is a critical step. Your installations will fail otherwise. To update apt-get, at the SSH prompt enter the following below, then go get a coffee. This can take about 5-10 minutes to run.
sudo apt-get update
Step 5: Install a Linux Desktop
With that complete you can now install a desktop package. There are a number you can choose from, I am really becoming a big fan of XFCE. It is extremely light weight and takes minutes to install versus Ubuntu Desktop which is a beast and includes things like Libre Office and other stuff I don’t need and can take up to an hour to download and install. To install XFCE, enter the following:
sudo apt-get install xfce4
Step 6: Install RDP on Linux
With your desktop successfully installed you can now install RDP on the Linux VM. To install this simply type:
sudo apt-get install xrdp
Step 7: Open the Windows RDP Client
We now have the RDP service running on Linux and a desktop into which we can log into. Next open the Remote Desktop Connection in Windows and type in the host name of your VM.
Tip: Be sure to type in the name you used when you created the VM and click “Save” under Connection Settings. If you don’t do this Windows will stubbornly try to log you in to the VM using your cached Windows credentials.
Step 8: Login
Next click Connect in Windows RDP client and enter your Linux VM password in the dialog shown here.
Note: If you’re seeing your cached Windows credentials in the username, hit cancel and go back to the RDP client in Windows and enter your user name again and then click, Save.
Step 9: Enjoy your new Linux dev machine
And that’s it. If you’re using XFCE you’ll see this when you first log in. Just select Use Default Config.
You can then begin customizing your desktop environment, installing other packages, applications, etc. and start using your VM as a Linux dev environment.