0
0
AzureHow-ToBeginner · 3 min read

How to Configure Azure CLI: Setup and Usage Guide

To configure Azure CLI, first install it, then log in using az login. After login, set your default subscription with az account set --subscription <subscription-id> to manage resources easily.
📐

Syntax

The basic commands to configure Azure CLI include:

  • az login: Logs you into your Azure account.
  • az account list: Lists all subscriptions linked to your account.
  • az account set --subscription <subscription-id>: Sets the default subscription for commands.
  • az configure: Allows setting default output format and other preferences.
bash
az login
az account list
az account set --subscription <subscription-id>
az configure
💻

Example

This example shows how to log in, list subscriptions, and set a default subscription for your Azure CLI session.

bash
az login
az account list --output table
az account set --subscription 12345678-1234-1234-1234-123456789abc
az configure --defaults group=myResourceGroup location=eastus
Output
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ABCD1234 to authenticate. Name CloudName SubscriptionId State IsDefault ----------------- ----------- ---------------------------------- ------- --------- My Subscription AzureCloud 12345678-1234-1234-1234-123456789abc Enabled True Defaults updated successfully.
⚠️

Common Pitfalls

Common mistakes when configuring Azure CLI include:

  • Not logging in before running commands, causing authentication errors.
  • Using the wrong subscription ID or forgetting to set the default subscription, leading to resource creation in unintended subscriptions.
  • Ignoring the output format, which can make reading command results harder.

Always verify your login status and subscription with az account show before running resource commands.

bash
## Wrong way: Running commands without login
az group list

## Right way: Login first
az login
az group list
📊

Quick Reference

CommandDescription
az loginAuthenticate to your Azure account
az account listList all subscriptions
az account set --subscription Set default subscription
az configureSet default output and other preferences
az account showShow current subscription details

Key Takeaways

Always run az login before using Azure CLI commands.
Set your default subscription with az account set --subscription <id> to avoid mistakes.
Use az configure to customize your CLI experience.
Check your current subscription anytime with az account show.
Remember to verify your login and subscription to prevent errors.