Azure Command Line Interface (Azure CLI) is a convenient way to manage, update, and create resources on the Microsoft Azure cloud platform. Azure CLI can be used for any Azure service, and it is designed with automation in mind.
The Azure CLI allows you to easily work in all popular programming languages and environments. In this article we focus on using the Azure CLI in an Azure Linux environment.
It also provides powerful features you can use to automate resources on Azure:
In this article, you will learn:
If you use the distribution provided by apt (such as Debian or Ubuntu), or use the x86_64 package in the Azure CLI—note the package was tested and is compatible with the following products:
There are two ways to install Azure CLI using apt-compatible deployment. One is to run a general installation command script, and the other is a step-by-step process that can be run directly.
Azure provides and maintains scripts that can run all installation commands using one line of code. You can run these one line scripts using curl. An alternative is downloading the script into a file, where you can check it before actually running. Here is a one-line script for installing the Azure CLI:
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
If you are not interested in running the script as root, or the one-line script does not work, follow the steps below to install Azure CLI.
sudo apt-get update
sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg
curl -sL https://packages.microsoft.com/keys/microsoft.asc |
gpg --dearmor |
sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" |
sudo tee /etc/apt/sources.list.d/azure-cli.list
sudo apt-get update
sudo apt-get install azure-cli
The following three tips will help you make the most out of your use of Azure CLI.
Most CLI update commands have three common parameters: --add, --set and --remove. Although these options are powerful, they are generally not as useful as the strongly typed options commonly used in update commands. The CLI provides strongly typed arguments for the most common situations for ease of use. However, if the property you need is not listed, you can rely on generic update arguments, to avoid waiting for a new release of the CLI.
The generic update syntax is not the easiest to use and requires a little patience. You must make sure that the Generic Update Arguments group exists. If not, you need to create a support ticket to make this group available as part of the update operation.
Once you have the group, try the following:
Azure CLI is often used on machines used to build software packages using CI/CD systems such as Jenkins. These types of machines commonly run several builds at the same time, with different users running different builds. This creates a need to log into the CLI several times with different users.
To avoid an issue where the same login token will be shared between all the builds, on each build system, set the AZURE_CONFIG_DIR environment variable to a directory that contains a correct login token for that build system.
Next, see how to deploy a Linux virtual machine (VM) in Azure using the Azure Command Line Interface (CLI).
Related content: read our guide to Azure Linux VMs
Azure Cloud Shell is a free interactive shell that can be used to complete the steps in this tutorial. All popular Azure tools are pre-installed and configured to work with your account. You can open CloudShell from a browser tab using this URL: https://shell.azure.com/bash
Use the az group create command to create a resource group. Azure resource groups are logical containers in which Azure resources are organized and managed. See an example below:
az group create --name myResourceGroup --location eastus
Use the azvmcreate command to create a virtual machine. Below is an example showing how to create a VM named myVM and adds a user account to it.
The --generate-ssh-keys option is used to automatically generate SSH keys and save them in the standard key location (~/.ssh). The --ssh-key-value parameter lets you specify which set of keys to use in the vm create operation. It can take a few minutes for the VM to be launched.
az vm create --resource-group myResourceGroup --name myVM \
--image UbuntuLTS --admin-username azureuser --generate-ssh-keys
Azure NetApp Files is a cloud service provided by Azure and NetApp, which lets you manage file shares in Linux with enterprise-grade performance and built-in high availability.
You must first register for Azure NetApp Files and create a NetApp account - see instructions here.
Use this command to create a capacity pool, which you can later use to create enterprise-grade NFS volumes and mount them to Linux VMs in Azure, or to Linux machines running on premises.
Under service-level, you can select Standard, Premium, or Ultra to define the performance and availability you need from your file shares (learn about service levels).
az netappfiles pool create \
--resource-group {your-resource-group} \
--location {required-location} \
--account-name {your-account} \
--pool-name "mypool1" --size {size-in-TB} \
--service-level "Premium"
First, create a virtual network. We will not create a subnet at this stage, in the next step we’ll create a delegated subnet.
az network vnet create --resource-group {your-resource-group} \
--name "myvnet1" --location {required-location} \
--address-prefix "10.7.0.0/16"
Now let’s create the delegated subnet, this will allow the NFS volume to run privately and securely.
az network vnet subnet create --resource-group {your-resource-group} \
--vnet-name "myvnet1" --name "mysubnet1" \
--address-prefixes "10.7.0.0/24" \
--delegations "Microsoft.NetApp/volumes"
Finally, we can create the volume itself. Note that the file path you provide must be unique to the Azure subscription and region, you cannot create another NFS share on the same path.
Under protocol-types, select the NFS version your applications support - Azure NetApp Files support NFSv3 and NFSv4.1.
az netappfiles volume create --resource-group {your-resource-group} \
--location {required-location} --account-name {your-account} \
--pool-name "mypool1" --name "myvol1" \
--service-level $SERVICE_LEVEL \
--vnet "myvnet1" \
--subnet "mysubnet1" \
--usage-threshold {size-in-TB} \
--file-path {unique-file-path} \
--protocol-types "NFSv3"
Azure NetApp Files is a Microsoft Azure file storage service built on NetApp technology, giving you the file capabilities in Azure even your core business applications require.
Get enterprise-grade data management and storage to Azure so you can manage your workloads and applications with ease, and move all of your file-based applications to the cloud.
Azure NetApp Files solves availability and performance challenges for enterprises that want to move mission-critical applications to the cloud, including workloads like HPC, SAP, Linux, Oracle and SQL Server workloads, Windows Virtual Desktop, and more.
In particular, Azure NetApp Files allows you to migrate your Linux applications to Azure–even your business-critical workloads–with extreme file throughput with sub-millisecond response times.
Want to get started? See Azure NetApp Files for yourself with a free demo.