⌨️ The Azure CLI (az): Sign In, Defaults, Output and Query
How the az command is organized, the four ways to sign in, how to set a default subscription, resource group and region, how to shape the output with --output and --query, and how to ask for help with no account at all
💡 How this page was tested. Unlike the account, regions and services pages, parts of this one were run for real. On 6 October 2026 I installed Azure CLI 2.91.0 in a throwaway folder (with its own empty home directory, so nothing touched a real configuration) and ran everything that works without signing in: the version, the errors you see when you are not signed in, the defaults, --help, and a JSON query against the built-in list of clouds. Everything that needs a real account is marked from the documentation, not run here. The same approach is used on the AWS, Google Cloud and Oracle CLI pages, and the comparison page puts all four side by side.
What az is
az is the Azure command-line interface. Everything the portal can do, az can do, because they use the same front door: Azure Resource Manager (see the services map). The commands are organized as group, then subcommand, like az group create or az vm list:
- az group ... resource groups, az vm ... virtual machines, az storage ... storage, az network ... networking, az account ... subscriptions and sign-in.
- Every group has --help.
Getting it
You can install it from your system's package manager, the Microsoft installer for your platform, or with pip. The documentation lists the options for each system (from the documentation, not run here). I used pip in a virtual environment, because it leaves nothing behind when you delete the folder. Or skip installing: Cloud Shell (the terminal inside the Azure portal) has az ready and already signed in.
python3 -m venv venv-az venv-az/bin/pip install azure-cli
The version, as run:
user@lab:~$ az --version azure-cli 2.91.0 core 2.91.0 telemetry 1.1.0 Dependencies: msal 1.39.0 azure-mgmt-resource 24.0.0 Python location '.../venv-az/bin/python3' Config directory '~/.azure' Extensions directory '~/.azure/cliextensions' [...] Your CLI is up-to-date.
(Your CLI is up-to-date means it checked Microsoft's servers for a newer one. The config directory is ~/.azure: that folder is where it keeps your sign-in tokens, so treat it like a password file.)
Before you sign in
Run these three first. They are safe, and they show what an unsigned CLI says:
user@lab:~$ az account show ERROR: Please run 'az login' to setup account. user@lab:~$ az account list --output table WARNING: Please run "az login" to access your accounts. user@lab:~$ az vm list ERROR: Please run 'az login' to setup account.
Please run 'az login' to setup account. is the message that means "you are not signed in". Note that az account list printed a warning and an empty list (rather than an error), which is easy to misread as "no subscriptions".
Signing in
From Microsoft's documentation (read on 6 October 2026), four ways:
- Cloud Shell. Already signed in. The easiest way to start.
- az login (interactive). Opens a browser, and then offers a subscription selector to set the default. The documentation says it is good for learning and running locally. The help text adds: on a machine without a browser it falls back to device-code login (you open a link on another device and type a code). You can ask for that directly with az login --use-device-code.
- A managed identity. For code running on Azure (a VM, a function). No secrets at all.
- A service principal. For scripts and automation. Microsoft recommends it, with just the permissions the job needs.
Two facts to know:
- MFA is required for command-line sign-in. Microsoft says that from September 2025 it requires multi-factor authentication for the Azure CLI and other command-line tools for user identities. A script that signs in with a user name and password will stop working: move it to a service principal or managed identity. The help text of az login also warns that "authentication with username and password in the command line is strongly discouraged".
- Tokens are stored locally. After a user sign-in, the CLI keeps a refresh token in ~/.azure. Anyone who can read it can act as you until it expires or you run az logout.
After signing in, check where you are (from the documentation, not run here):
az account show az account list --output table az account set --subscription "SUBSCRIPTION NAME OR ID" az logout
az account set chooses the subscription that the following commands use. If you have more than one, run az account show before every experiment.
Defaults: stop typing the same flags
Most commands need a resource group and a location. You can set defaults once, and the commands use them. This part ran for real (no sign-in is needed to store a setting):
user@lab:~$ az config set defaults.location=westeurope defaults.group=lab-rg
WARNING: Command group 'config' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
user@lab:~$ az config get
WARNING: Command group 'config' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
{
"cloud": [
{
"name": "name",
"source": "~/.azure/config",
"value": "AzureCloud"
}
],
"defaults": [
{
"name": "location",
"source": "~/.azure/config",
"value": "westeurope"
},
{
"name": "group",
"source": "~/.azure/config",
"value": "lab-rg"
}
]
}
user@lab:~$ cat ~/.azure/config
[cloud]
name = AzureCloud
[defaults]
location = westeurope
group = lab-rg
- az config set defaults.location=westeurope defaults.group=lab-rg wrote the two settings. (az config says it is experimental, which is why the warning appears: az configure --defaults location=westeurope group=lab-rg is the older command for the same job.)
- az config get shows each setting and which file it came from. The file is plain text, ~/.azure/config.
- The defaults reach into the help. Here is az group create --help after setting a default location:
user@lab:~$ az group create --help | sed -n 1,16p
Command
az group create : Create a new resource group.
Arguments
--name --resource-group -g -n [Required] : Name of the new resource group.
--location -l : Location. Values from: `az account list-locations`.
You can configure the default location using `az
configure --defaults location=<location>`. Config:
westeurope.
--managed-by : The ID of the resource that manages this resource
group.
--tags : Space-separated tags: key[=value] [key[=value] ...].
Use '' to clear existing tags.
Global Policy Arguments
Look at the --location entry: it ends with Config: westeurope. The help tells you that a default is in force. This is a double-edged tool: a forgotten default location puts new things in a region you did not choose, so look at az config get when something lands in a surprising place. To remove one: az config unset defaults.location.
Output: json, table, tsv and the rest
Every command takes --output (or -o). From the help text of the real CLI, the choices are json (the default), jsonc (colored), table, tsv (tab-separated, no headers), yaml, yamlc and none. When to use which:
- -o table for reading at the terminal.
- -o tsv for scripts: one value, no quotes, no headers, so $(az ... -o tsv) gives you a clean string.
- -o json to see everything a command returns and decide what to pick.
- -o none when you only care that it worked.
--only-show-errors hides warnings, --verbose adds detail and --debug shows every request (this is where you look when a command fails in a way you cannot explain).
Query: pick exactly what you want
--query takes a JMESPath expression, the same little language the AWS and Oracle CLIs use (the comparison page has a primer). It runs on the CLI's side, after the answer arrives. These examples ran for real on az cloud list, which is built into the CLI (a list of Azure clouds, no account needed):
user@lab:~$ az cloud list --output table
IsActive Name Profile
---------- ----------------- ---------
True AzureCloud latest
False AzureChinaCloud latest
False AzureUSGovernment latest
False AzureBleuCloud latest
user@lab:~$ az cloud list --query '[].name' --output tsv
AzureCloud
AzureChinaCloud
AzureUSGovernment
AzureBleuCloud
user@lab:~$ az cloud list --query "[?isActive].{Name:name, ARM:endpoints.resourceManager}" --output json
[
{
"ARM": "https://management.azure.com/",
"Name": "AzureCloud"
}
]
user@lab:~$ az cloud list --query "[].{Name:name, Portal:endpoints.portal}" --output table
Name Portal
----------------- --------------------------------
AzureCloud https://portal.azure.com
AzureChinaCloud https://portal.azure.cn
AzureUSGovernment https://portal.azure.us
AzureBleuCloud https://portal.sovcloud-azure.fr
Read them in order:
- --output table prints everything as a table.
- --query '[].name' --output tsv: [] means "every item in the list", .name is the field. With tsv you get one name per line, ready to loop over.
- --query "[?isActive].{Name:name, ARM:endpoints.resourceManager}": [?isActive] filters (only items where isActive is true), and {Name:name, ARM:...} builds a new object with the fields you choose and the names you give them. It also reaches into nested data: endpoints.resourceManager.
- The same shape with --output table gives a clean table with your own column names.
The same techniques on a real subscription (from the documentation, not run here):
az vm list --output table
az vm list --query "[].{Name:name, Size:hardwareProfile.vmSize, State:powerState}" --show-details --output table
az account show --query id --output tsv
az group list --query "[?location=='westeurope'].name" --output tsv
(--show-details makes az vm list fetch the power state.) The note on JMESPath: field names are case-sensitive, string values in a filter go in single quotes, and the whole expression goes in double quotes in the shell, so the quotes do not fight.
Getting help, with no account
Help is built in, runs locally and needs no sign-in:
- az --help, az group --help, az vm create --help. The help shows every argument, marks the [Required] ones, and lists examples at the end.
- az find "az group create" looks up examples and documentation. (It contacts a Microsoft service to find them, so unlike the other commands on this page it needs the network.)
- az interactive starts an interactive shell with autocomplete (it installs an extension first).
Habits that save you
- Run az account show first. Wrong subscription is the most common mistake.
- Keep a --output table habit at the terminal and -o tsv in scripts.
- Use --no-wait for slow commands (deleting a group, creating a VM) and check later: for example az group delete --name demo-rg --yes --no-wait.
- In scripts, use a service principal or a managed identity, not your own sign-in, and never put a secret in the script or in the shell history.
- Test with --help and with a throwaway resource group (see the tidy-experiment pattern on the services map).
- Check the exit code in scripts: az returns non-zero on failure.
The cheat sheet
- Shape: az GROUP SUBCOMMAND --option value. Help: -h or --help at any level.
- Not signed in: Please run 'az login' to setup account. Sign in: az login (browser, or --use-device-code). Scripts: service principal or managed identity. MFA is required for user sign-in.
- Where am I: az account show, az account list --output table, az account set --subscription X.
- Defaults: az config set defaults.location=X defaults.group=Y, az config get, file ~/.azure/config.
- Output: -o json|jsonc|table|tsv|yaml|yamlc|none. Query: --query "[?field=='x'].{Name:name}" (JMESPath).
- Debug: --verbose, --debug, --only-show-errors.
- Clean up: az group delete --name X --yes --no-wait.
↑ All tutorials · The AWS CLI (aws): Sign In, Profiles, Output and Query →