Creating a Linux Virtual Machine From the Command Line
In this post we'll create an Azure account, install the Azure command line tool and use it to create a Linux Virtual Machine within your newly minted Azure account.
Getting setup on Azure
The first order of business is to get get a new Azure account. Head of to azure.microsoft.com to get started.
Before you sit down to do this you'll need a microsoft.com account, a credit card and your cell phone for verification purposes. You'll find this experience relatively painless and in no time you'll be inside the Azure portal. They have have some simple walk-throughs for you once you are inside. To make your reading of this article more entertaining I'll actually spin up an Ec2 instance in AWS, install the Azure Command line Interface on it and then proceed to create a Linux machine from the command line. We'll finish by shelling into Azure from AWS.
Install Azures Command Line Tool
When I did this experiment I ran right off an Ubuntu Server Ec2 instance. However, there is really no necessity in doing this. You can certainly get this up and running straight from your local command line. To get the Azure command line tool installed run the following commands
sudo agt-get update sudo apt-get install nodejs-legacy sudo apt-get install npm sudo npm install -g -azure-cli -g
With the last command being executed the Azure command line tool will be installed and you can verify the version by running
azure --version as show below.
Logging into Azure from the Command Line
Microsoft makes this easier than you would'd think. Simply running the command
azure login and url with security token will be returned. To successfully authenticate all you need to do is follow the url and enter the security token in the browser. Here is what it looks like.
Following the url in the browser completes the authentication step.
Creating a Linux Box from the Command Line
At this point you are ready to create a virtual instance. This is just a matter of knowing the right commands and giving a correct configuration. Start the configuration by running
azure config mode arm. This will allow you to configure Azure resources in the command line context. You also need to create a new resource group. Keep note of what you call your group because you'll need it again when you go to create the actual instance.
azure group create blogTest eastus will create the "blogTest" group in the eastus region. At this point you need to run some commands to allocate the foundational resources to create your instance. To this end run
azure provider register Microsoft.DataFactory and then
azure account list. Here you will see your fee account listed with it's id. To complete this resource allocation run
azure account set <SubscriptionId> Where
azure vm quick-create. You'll then be prompted for several things, but keep in mind your previous group name and the fact that you allocated resources in eastus. You'll be prompted to create user-name and password. Be sure to keep note of them. The only odd ball thing you'll be asked for is the ImageURN. You can create an Ubuntu image with the input
canonicalubuntuserver:14.04.2-LTS:standard Since you are working from the command line Microsoft does insist on a minimal password length of 8. Here is a screen capture of this whole process so you can try it for yourself.
This process will take a few minutes but when it completes a summary will be echoed to the terminal. This summary will in particular give the fully qualified domain name of your new instance that will allow you to shell into it. Below is completion the creation process.
ssh and Kick The Tires!
At this point you have made an Ubuntu instance on Azure from the command line and are ready to shell into it. From the summary screen above we have sufficient credentials to login. Indeed, running
ssh [email protected]avndl262-pip.eastus.cloudapp.azure.com and using the password you chose earlier we will be fully logged into our new instance. Below is a screen capture of the full login process.
Back to the Azure Portal
Return to your actual Azure Portal in your browser and see all the resources you just created from the command line have updated into the portal. Here's how mine looks now.
We didn't need the command line to accomplish this but it let us explore and combine facets of Azure in a non obvious way.
AWS or Azure?
So which cloud platform is better? That is a deep question. Personally, most of my cloud computing experience has been with Amazon but I do have to say Microsoft has made a very smooth and seamless user experience. I think a complete answer to that question would be both platforms have their strengths and weakness but the correct tool for the job depends on the specific task at hand. If you learn one platform well and ignore the alternatives then you might miss the optimization that another platform could give you. When the only tool you have is a hammer it's funny how everything start to look like a nail.