---
title: "Master Azure CLI: Command Your Cloud with Confidence"
description: "Unlock the full potential of cloud management with the Azure CLI. This guide provides the essentials to get you started with Azure resources efficiently."
canonical: "https://adamtheautomator.com/azure-cli/"
---

# Master Azure CLI: Command Your Cloud with Confidence

> Unlock the full potential of cloud management with the Azure CLI. This guide provides the essentials to get you started with Azure resources efficiently.

Source: https://adamtheautomator.com/azure-cli/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Master Azure CLI: Command Your Cloud with Confidence](https://adamtheautomator.com/wp-content/uploads/2021/03/azure-cli.jpg)

# Master Azure CLI: Command Your Cloud with Confidence

[![](https://secure.gravatar.com/avatar/75fa5f572fb085a46bfff406309882e0848db4770557901e8de897b3f7d05a7a?s=192&d=mm&r=g)Nick Rimmer](https://adamtheautomator.com/author/nick/)29 December 202310 min. read

Categories: [Cloud](/category/cloud/)

Tags:[Microsoft Azure](/tag/microsoft-azure/)

Table of Contents

*   [Prerequisites](#h-prerequisites)
*   [Getting Help with az help](#h-getting-help-with-az-help)
*   [Navigating a Typical Help Example](#h-navigating-a-typical-help-example)
*   [Finding Syntax Examples with az find](#h-finding-syntax-examples-with-az-find)
*   [Assigning a Default Configuration with az configure](#h-assigning-a-default-configuration-with-az-configure)
*   [Setting Default Parameter Values](#h-setting-default-parameter-values)
*   [Authenticating with a Browser](#h-authenticating-with-a-browser)
*   [Authenticating Using a Device Code](#h-authenticating-using-a-device-code)
*   [Azure CLI Output Options](#h-azure-cli-output-options)
*   [Creating a Resource Group](#h-creating-a-resource-group)
*   [Creating A Linux Virtual Machine](#h-creating-a-linux-virtual-machine)
*   [Next Steps](#h-next-steps)

If you have a Microsft Azure account and are still managing resources only through the Azure Portal, you’re missing out. One of the best ways to reduce clicking and increase productivity is by using the Azure CLI.

The Azure CLI is a cross-platform toolset written in Python that allows you to manage nearly all of your Azure resources from the command line. No matter what operating system you’re on, the Azure CLI provides a consistent experience across all platforms.

In this tutorial, you’re going to learn how to get started with the Azure CLI. You’ll learn how to perform an initial configuration and create and remove some common resources using various Azure CLI commands.

## Prerequisites

This article will be a tutorial. If you plan on following along step-by-step, you will need at least one of the following:

*   Azure CLI – This tutorial will be using v2.20.0 on a Docker Container, but the commands will work all the same on other platforms.

Related:[How to Install the Azure CLI (Windows, Linux, macOS, Azure Shell)](https://adamtheautomator.com/install-azure-cli/)

*   An [Azure Cloud account](https://azure.microsoft.com/en-gb/) – This tutorial can be done using the free account.
    
*   Permissions to create resources within Azure via a Microsoft account perhaps using a [service principal](https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli).
    

Related:[Azure Service Principals: How to Create (And Understand) Them](https://adamtheautomator.com/azure-service-principal/)

## Getting Help with `az help`

Before you run any command in the Azure CLI, learn how to use the `az help` command. The Azure CLI has rich and plentiful help in the Azure CLI. This tutorial can’t possibly cover all commands so learning how to use `az help` is critical.

To get started, let’s navigate around the help system and check out how to find further information on various commands.

### Navigating a Typical Help Example

Examples make the best learning material. Let’s cover how to use the Azure CLI help system by walking through an example of finding the needed command to create a [resource group](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/manage-resource-groups-portal) in Azure.

With your terminal open:

1\. Run the `az help` command. This command returns two types of output; groups and subgroups.

> _Commands are organized as groups. You’ll typically see tutorials (and even documentation) refer to groups as “commands”. Groups are broken out in a hierarchical fashion with each group representing an Azure service._

![output of az help](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T104031.446.png)

output of az help

2\. Scroll down until you find the subgroup called `group`. You can see from the description below, this subgroup is responsible for managing resource groups. _Groups are ordered alphabetically._

![scrolling down to find group](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T104124.442.png)

scrolling down to find group

3\. Once you’ve found the command you’re looking for, run it using the `--help` parameter. Using the `--help` parameter doesn’t make any changes; it returns all help documentation for a group or command.

```bash
az group --help
```

You can see below the `group` group and a single subgroup (`lock`) with various commands inside.

![output of az group help](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T104436.620.png)

output of az group help

4\. Since you want to create a resource group, the `create` command looks like the right command. Now continue getting more specific by appending a more granular command to the original `az group` reference and finding help.

```bash
az group create --help
```

> _Reference the `--help` parameter on any command to see it’s help documentation._

The `--help` parameter now displays information about the `create` command. Commands have arguments as shown below. In this example, you now have the arguments required to specify a resource group and required `location`.

![help parameter](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T104634.487.png)

help parameter

### Finding Syntax Examples with `az find`

If you can’t easily find the group or command you’re looking for with the `--help` parameter, take a look at the `az find` command. This command searches for syntax examples using group/command references as shown below.

For example, instead of navigating the help system with `--help` as shown above, perform the same task with a single line with `az find`.

```bash
az find "az group create"
```

![output of find command](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T154521.827-1.png)

output of find command

## Assigning a Default Configuration with `az configure`

The Azure CLI has many commands and features. Each of these features has various configurations they reference like logging and data collection preferences. One of the first tasks you should complete when setting up the Azure CLI for the first time is running the `az configure` command.

In one command, the `az configure` command walks you through three different settings:

*   Output Format – Seven different different ways that the Azure CLI returns output
*   Logging – The ability to log all Azure CLI activity to a file
*   Telemetry – To enable or disable sending information to Microsoft about how you use Azure CLI

To get started, assuming you already have the [Azure CLI installed](https://adamtheautomator.com/install-azure-cli/):

1\. Open a terminal (Bash or PowerShell).

2\. Type in the command `az configure`. You’ll be prompted with a simple menu letting you know that all settings will be stored in the _.azure/config_ file. Press Y to continue.

![output from azconfigure](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T154625.158-1.png)

output from azconfigure

3\. The command will first prompt you for your desired default output format. Here, pick your desired output. The default output format sets how your output will appear on the screen after executing a command or receiving an error message.

![If you're unsure, below you'll find some examples.](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T154807.213.png)

If you’re unsure, below you’ll find some examples.

> _The below examples use the `output` parameter. Regardless of what format you pick as the default, you can always override the default output with the `output` parameter._

[JSON](https://www.w3schools.com/whatis/whatis_json.asp#:~:text=JSON%20stands%20for%20JavaScript%20Object,describing%22%20and%20easy%20to%20understand) (Java Object Notation)

![json output](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T154900.139.png)

json output

[JSONC](https://github.com/json-c/json-c) (Java Object Notation with comments\\colorization)

![jsonc output](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T154946.656.png)

jsonc output

Table

![table output](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T155027.835.png)

table output

[TSV](https://whatis.techtarget.com/fileformat/TSV-Tab-separated-values-file) (Tab-Separated Values)

![tsv output](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T155114.600.png)

tsv output

[YAML](https://yaml.org/) (YAML Ain’t Markup Language)

![yaml output](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T155200.713.png)

yaml output

YAMLC (YAML with comments\\colorization)

![](https://adamtheautomator.com/wp-content/uploads/2021/03/image-9.png)

yamlc output

None – The Azure CLI will only return errors or warning.

4\. Once you’ve set the output format, the Azure CLI will prompt you to enable logging. Here, select `Y` to enable logging all commands and output to a file.

![Output Format](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T155406.008.png)

Output Format

Selecting `Y` here will create a log containing all the commands and output collected while using the CLI. This log is located in the _$HOME/.azure/logs_ directory in Linux and macOS and _%USERPROFILE%\\.azure\\logs_ in Windows.

Below you can see an example of what the log would look like.

![Log file contents after executing az login](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T155528.072.png)

Log file contents after executing `az login`

5\. The Azure CLI will then ask you to send telemetry data to Microsoft. Selecting `Y` here will send anonymous information to Microsoft on how you use the Azure CLI.

![Telemetry Data](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T160135.987.png)

Telemetry Data

> _For more information on the information that Microsoft collects, refer to [Microsoft’s privacy information](https://github.com/Azure/azure-cli/blob/dev/LICENSE) on collecting anonymous data from Azure CLI._

Finally, `az configure` will ask to set the CLI object cache time-to-live value. You should leave this set at the default of 10.

![cli object cache setting ](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T160311.681.png)

cli object cache setting

> _Only change the CLI object TTL if advised by Microsoft when troubleshooting an issue with the Azure CLI._

## Setting Default Parameter Values

The Azure CLI has various commands with the same parameters such as location and group. Rather than key in the values for these parameters every time for every command, you can set default parameter values.

To set parameter defaults, use the `--defaults` parameter on `az configure`. This parameter allows you to define a parameter and it’s default value. For example, perhaps you’re tired of typing in a `location` and `group` for various commands. No problem. Set a couple of default values.

The following example sets the default region (`location`) to `westus2` and the resource group (`group`) to `MyResourceGroup`. Now whenever you run any Azure CLI command that has a `location` or `group` parameter, Azure CLI will automatically pass values to those parameters.

```bash
az configure --defaults location=westus2 group=MyResourceGroup
```

> If you are using containers, you could set individual containers to manage specific regions, subscriptions or resource groups by setting the defaults in each container instance. You could create 4 containers in each container using az configure to set a default region and a default resource group using the command above.

## Authenticating with a Browser

You’ve now learned the basics of using the Azure CLI, but you haven’t actually done anything yet. Let’s now take that step into creating some resources! But first, you must log in to Azure, using the command, `az login`.

> _If you have multiple Azure subscriptions, run the `az account list` command to find all subscriptions. When you find the subscription, run `az account set --subscription <subscription name>` to set the subscription to use for the session. You can also use the global `subscription` parameter to explicitly specify a subscription._

1\. Open a terminal and run `az login`. This command opens a browser window that takes you to a page to provide your username and password.

![az login in Powershell session](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T160513.414.png)

az login in Powershell session

2\. Provide your Azure account credentials or click on an existing user account as shown below.

![authenticate with Microsoft](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T160609.006.png)

authenticate with Microsoft

3\. Once Azure authenticates your account, close your web browser and return to your Azure CLI session. The `az login` command returns information about your subscription to confirm you now have an authentication token.

![Output from az login, once authenticated](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T160711.732.png)

Output from az login, once authenticated

## Authenticating Using a Device Code

If you’re on a system without a browser or want to download an authentication token on another computer, use the `--use-device-code` parameter. This parameter allows a user to use a code supplied from another device to authenticate the user.

To authenticate using a device code, open a terminal and:

Run `az login` using the `--use-device-code` parameter. The `az login` command, this time, will not open a browser. Instead, it will provide a code to provide to the device login page on another computer.

```bash
az login --use-device-code
```

![output of az-login —use-device-code](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T160900.117.png)

output of az-login —use-device-code

2\. On a _different_ computer, navigate to [https://microsoft.com/devicelogin](https://login.microsoftonline.com/common/oauth2/deviceauth), paste in the code supplied, and click **Next**.

![Enter code to authenticate](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T160956.582.png)

Enter code to authenticate

3\. Now enter your credentials to authenticate to Azure and close your browser, if not needed.

![choosing an account to authenticate with](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T161041.241.png)

choosing an account to authenticate with

Back in the Azure CLI session, `az login` will return your subscription information.

![verification your session is logged on to azure](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T161128.803.png)

verification your session is logged on to azure

## Azure CLI Output Options

As mentioned, the Azure CLI can return output in different ways. You can define the default output and change it on the fly with the `output` parameter. But the `output` parameter isn’t the only parameter that changes output behavior.

To change up the verbosity, filter output or modify error output behavior, use the following parameters.

*   `query` – Uses the [JMESPath](https://jmespath.org/) query language to filter output for all commands. Reference [this article](https://docs.microsoft.com/en-us/cli/azure/query-azure-cli) to learn more.
*   `verbose` – Returns information about resources created in Azure and extended information about those resources.
*   `debug` – Returns a low-level amount of information about CLI operations used for debugging.
*   `only-show-errors` – Show errors and suppress warnings.

## **Creating a Resource Group**

Now that you’re authenticated to Azure, you’re free to manage all of the resources you have permission to. Let’s first run through a common example of creating a resource group.

Assuming you’re on a computer with the Azure CLI installed and you’ve already authenticated to Azure with the CLI:

Create a resource group using the `az group create` command as shown below. This command is creating a `resource-group` called _TESTGrp_ in the North Europe `location` and returning all `verbose` output.

```bash
az group create --location northeurope --resource-group TESTGrp --verbose
```

![output of az group create](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T162536.943.png)

output of az group create

2\. Now confirm Azure created the resource. `az group list`

```bash
az group list
```

Notice that you’ve created the _TESTGrp_ resource group.

![output of az group list](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T162728.812.png)

output of az group list

3\. Perhaps you have a lot of resource groups to sift through. Instead of scrolling, use the `query` parameter to narrow down the list. The below command only returns resource groups in the North Europe `location` using [JMESPath](https://jmespath.org/).

```bash
az group list --query "[?location=='northeurope']"
```

![output of a JMESPath query](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T162843.811-1.png)

output of a JMESPath query

## Creating A Linux Virtual Machine

For this last example, learn how to create an [Azure VM](https://azure.microsoft.com/en-us/services/virtual-machines/) with the Azure CLI. Creating virtual machines and the configuration around them is a good skill to learn. Creating Azure VMs is a common task you may perform repeatedly during your cloud journey.

In this exercise, you’ll create an Azure Linux VM with default settings and deploy it into the resource group created in the previous section.

An Azure VM consists of many Azure resources all working together like a disk image, virtual network adapter, virtual machine, and so on.

To create an Azure VM with the Azure CLI:

1\. Run the `az vm image list` command to find all available VM images for the VM. This command returns all of the cached/offline images. `az vm image list`

```bash
az vm image list
```

For this demo, choose the `UbuntuLTS` image as highlighted below.

![Cached list of images available ](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T163036.726.png)

Cached list of images available

> _The Azure CLI maintains a cached list of all VM images. If the UbuntuLTS image doesn’t show up, use the `all` parameter to get an updated list._

2\. Once you know the disk image to use for the VM, create the VM with `az vm create`. The code snippet below creates a VM `name` of _ATAVM1_ using the UbuntuLTS `image` in the `resource-group` _TESTGrp_. When Azure creates the VM, it will generate the SSH keys (`generate-ssh-keys`) to connect to it later and return output in JSON (`output`).

```bash
az vm create --resource-group TESTGrp \
   --name ATAVM1 \ ## hostname for the virtual machine
   --image UbuntuLTS \ ## Image name gathered with az vm image list
   --generate-ssh-keys \ ## Auto generates SSH keys for use with VM
   --output json \ ## override for format output to return JSON
   --verbose ## extra output
```

> _Split a single longer Azure CLI commands on separates lines using a trailing backslash._

> _The `az vm create` command has many more ways to configure building a VM. Remember the help system is your friend! `az vm create --help`_

If the command was initiated successfully, you should see something similar to the screenshot below.

![VM being created ](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T163321.350.png)

VM being created

> _By using the `verbose` parameter, you will see the actual REST API method and parameters used in green._

3\. When the deployment completes, the last section of the output will display information about your VM. Most notably for this demo, copy the public IP address. You’ll need this to connect to the VM over the Internet.

![output from vm creation](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T163410.435.png)

output from vm creation

At this point, now connect to the Ubuntu VM via SSH using the VM’s public IP address found above. To do so, open your favorite SSH client and connect to the VM as the user _azureuser_ as shown below. By default, the `az vm create` command creates a local user called _azureuser_.

Related:[Setting up SSH in Linux](https://adamtheautomator.com/ssh-command-in-linux/#Connecting_to_Linux_from_Windows)

```bash
ssh azureuser@52.169.255.149
```

![connected to the vm created ](https://adamtheautomator.com/wp-content/uploads/2021/03/Untitled-2021-03-20T163616.445.png)

connected to the vm created

> _You were able to SSH to the VM without a password because you used the `generate-ssh-keys` parameter when creating the VM. This downloads the private key to your ~/.ssh directory and uploads the public key to the VM allowing you to authenticate._

5\. Now clean up the VM and the resource group.

```bash
az group delete --name TestGRP
```

## Next Steps

You should now have the Azure CLI ready to go. You’re now ready to manage some resources! So what next?

*   [Azure CLI Interactive mode](https://docs.microsoft.com/en-us/cli/azure/interactive-azure-cli)
*   [Azure CLI Tools for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azurecli)
*   [Azure CLI Samples on GitHub](https://github.com/Azure-Samples/azure-cli-samples)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fazure-cli%2F&text=Master%20Azure%20CLI%3A%20Command%20Your%20Cloud%20with%20Confidence)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fazure-cli%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fazure-cli%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/07/featured_image-1.webp)

### [Microsoft Azure Certification Roadmap: Choose the Right Path](/azure-certification-roadmap-2/)

Choose the right Microsoft Azure certification for your career goals. Compare AZ-900, AZ-104, AZ-305, AZ-400, AZ-700, DP-700, study timelines, and 2026 retirements.

![](https://adamtheautomator.com/wp-content/uploads/2021/05/How-to-RenameMove-Azure-Resource-Groups-GUI-and-CLI.jpg)

### [Smart Ways to Rename Azure Resource Groups (GUI and CLI)](/rename-azure-resource-group/)

Unlock the secret to Rename Azure Resource Groups! Dive into our easy guide for reshaping your Azure landscape with Portal, PowerShell, and CLI techniques.

![](https://adamtheautomator.com/wp-content/uploads/2019/08/microsoft-graph.png)

### [Mastering PowerShell Graph API: Easy-to-Follow Insights](/powershell-graph-api/)

Master the PowerShell Graph API with our concise guide. Learn to access, read, and manage data effortlessly, enhancing your API skills quickly and efficiently.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
