Microsoft continues to deliver on their promise to embrace open source. With dozens of officially supported Linux distributions and open source services available on their Azure platform, anyone can deploy workloads to their cloud platform regardless of the operating system of choice. Today, we are going to show you how to set up the Microsoft Azure CLI and use it to launch a virtual machine in the cloud.

Installation of the CLI

Note that this article does assume that you have access to the Microsoft Azure Portal and you have signed up for either the free tier (consisting of 200 compute hours) or another account (corporate or Pay As You Go). This is important as we have to link the CLI to the associated account created during your registration.

The installation is relatively simple and is largely the same regardless of your Linux distribution. Be sure you have installed the npm package for your distribution (either “sudo yum install npm” or “sudo apt-get install npm” for most distributions). Once you have, you are going to use it to install the command line interface for Azure:

sudo npm install -g azure-cli

Once complete (and it will take a few minutes to install; like most Node.JS installations, there are a ton of dependencies that will install along with the actual packages we are after). We can test that the install was successful by executing:

azure --version

Which shows us the version installed. Perfect! Let’s move on to configuration.

Configure the CLI

A couple of quick items before we can use the CLI to launch a VM in our cloud infrastructure. First, we want to set up command line autocomplete. Just like pressing tab in Bash will autocomplete a directory name for us, we want to be able to type part of an Azure CLI command and see the available options that meet it (so typing “azure log[TAB]” would show us that “login” and “logout” are available options). We do that by doing the following:

azure --completion >> ~/
echo 'source ~/' >> ~/.bash_profile

Note that after adding this to your environment, you need to log out and back in (or just execute the source command above for the current session). Now we have to associate the CLI interface with the account you log in to the portal with. Again, at a command prompt, issue the following command:

azure login

Where you should see something like the following:

info: Executing command login
info: To sign in, use a web browser to open the page Enter the code XXXXXXXXX to authenticate.

You then need to open your browser to the indicated URL and enter the code you were provided. If you are not already logged in to the Microsoft Azure Portal with your account, you will be prompted to do so. The browser will accept your code, associate the account with the CLI tools, complete the login process and indicate you can close the browser window. Once you return to the CLI prompt, you will see “login command ok” if everything was done correctly. Finally, we need to indicate that this CLI is going to use the Microsoft Azure Resource Manager model for managing our resources (rather than the classic model). This is done with a simple:

azure config mode arm

That’s it, let’s launch our first virtual machine!

Launching a Simple VM

Most of the work is done now. Launching a VM in our environment is a simple command (note that there are a TON of options we could use here, but we are just exploring how we can launch a simple virtual machine using nothing but a single command now; we may do more advanced commands in later articles). Type the following to launch a VM and associate the current user’s SSH public key for login:

azure vm quick-create -M ~/.ssh/ -Q RHEL

This asks you a few questions that look like the following block:

info: Executing command vm quick-create
Resource group name: Default
Virtual machine name: myrheltest
Location name: East US
Operating system Type [Windows, Linux]: Linux
User name: user
+ Listing virtual machine sizes available in the location "eastus" 
+ Looking up the VM "myrheltest" 
info: Verifying the public key SSH file: /home/user/.ssh/
info: Using the VM Size "Standard_DS1"
[more output here...]

You are asked for a resource group, a name for your virtual machine, the zone to run it in and the operating system type. If you answer as I did above, you then get a bunch of informational output as your instance is created. The whole process should take three to five minutes to complete and you will see a message once it is done with all the information you need to use it (the output below is lengthy):

data: ProvisioningState :Succeeded
data: Name :myrheltest
data: Location :eastus
data: Type :Microsoft.Compute/virtualMachines
data: Hardware Profile:
data: Size :Standard_DS1
data: Storage Profile:
data: Image reference:
data: Publisher :RedHat
data: Offer :RHEL
data: Sku :7.2
data: Version :latest
data: OS Disk:
data: OSType :Linux
data: Name :cli00002599248831d3-os-1476457820250
data: Caching :ReadWrite
data: CreateOption :FromImage
data: Vhd:
data: Uri :
data: OS Profile:
data: Computer Name :myrheltest
data: User Name :user
data: Linux Configuration:
data: Disable Password Auth :true
data: Network Profile:
data: Network Interfaces:
data: Network Interface #1:
data: Primary :true
data: MAC Address :00-0D-3A-14-AA-4D
data: Provisioning State :Succeeded
data: Name :myrhe-eastu-mhflf3crqgd6-nic
data: Location :eastus
data: Public IP address :
data: FQDN
data: Diagnostics Profile:
data: BootDiagnostics Enabled :true
data: BootDiagnostics StorageUri :
data: Diagnostics Instance View:
info: vm quick-create command OK


You can now connect with either the Public IP or the FQDN as listed above. This whole process, start to finish, should take you less than fifteen minutes (including launching the VM). Be sure to check the Microsoft Azure documentation for more granular control over how your VM is configured, but right now, we have a full Red Hat VM available for use.

Get actionable training and tech advice

We'll email you our latest articles up to once per week.