← All cheatsheets

Cloud

Azure CLI — sign-in, subscriptions, and everyday operations

Everyday az CLI reference: authenticate, confirm which identity and subscription you are in, switch context and region, list and describe resources, tail logs, and run the few create/deploy ops people actually touch — read steps first, destructive and billable ones labeled.

Docs-checkedazureclirbacsubscriptionaksappservice

Quick reference — reach for these first

Who am I / what contextaz account show -o tableActive subscription, tenant, and signed-in user — run this before any change.
Sign inaz loginBrowser auth; headless hosts use az login --use-device-code.
Switch subscriptionaz account set --subscription SUBSCRIPTION_IDPoint every later command at the intended subscription.
List resourcesaz resource list -g RESOURCE_GROUP -o tableWhat exists in a group; drop -g to span the whole subscription.
Set default region + groupaz configure --defaults location=REGION group=RESOURCE_GROUPAzure has no global region; defaults save repeating -l / -g.

Authenticate → confirm context → read → scoped action → verify

Azure CLI auth and context confirmation flowSign in with az login, confirm the active subscription with az account show, set the correct subscription if wrong, then run a safe read, a scoped billable action, and verify.az loginaz account showright sub?az account setaz group list (read)az group create (billable)az group show (verify)yesno

Text equivalent: Flow: az login signs you in, az account show confirms the active subscription; if it is the wrong subscription, az account set switches it and you re-confirm; once correct you run a safe read (az group list), then a billable scoped action (az group create), then verify with az group show.

Common tasks

Task · Command · Check

TaskCommandCheck
Sign in interactivelyaz loginReturns a JSON array of subscriptions; az account show lists the expected user.
Sign in on a headless / remote hostaz login --use-device-codeDevice code is accepted in the browser; subscriptions are returned.
List subscriptions you can seeaz account list -o tableTarget subscription appears; IsDefault marks the active one.
Confirm the active identity and subscriptionaz account show --query "{user:user.name, sub:name, id:id}" -o tableUser and subscription id match what you intend to operate on.
Switch to the intended subscriptionaz account set --subscription SUBSCRIPTION_IDaz account show --query id -o tsv now returns SUBSCRIPTION_ID.
Set a default region and resource groupaz configure --defaults location=REGION group=RESOURCE_GROUPaz configure -l lists location and group defaults.
List resource groupsaz group list -o tableExpected RESOURCE_GROUP is present with its location.
List resources inside a groupaz resource list -g RESOURCE_GROUP -o tableExpected resources show with their types and locations.
List VMs with power stateaz vm list -d -o tablePowerState column shows running/stopped per VM.
Tail App Service logsaz webapp log tail -g RESOURCE_GROUP -n APP_NAMELive log lines stream; Ctrl-C to stop.
Pull AKS cluster credentialsaz aks get-credentials -g RESOURCE_GROUP -n CLUSTERkubectl config current-context points at CLUSTER.
List role assignments for a principalaz role assignment list --assignee PRINCIPAL_ID --all -o tableExpected roles and scopes are listed for that principal.
[BILLABLE] Create a resource groupaz group create -n RESOURCE_GROUP -l REGIONprovisioningState is Succeeded; appears in az group list.
[CHANGES ACCESS] Assign a role at a scopeaz role assignment create --assignee PRINCIPAL_ID --role Reader --scope SCOPENew assignment shows in az role assignment list --assignee PRINCIPAL_ID.

From zero: authenticate, confirm context, read, then one scoped action

auth-context

1
Sign in (browser opens; use --use-device-code on a headless host)
az login
# [ { "name": "Prod", "id": "SUBSCRIPTION_ID", "isDefault": true } ]
2
Confirm identity and subscription before touching anything
az account show --query "{user:user.name, sub:name, id:id}" -o table
# User                 Sub    Id
# you@contoso.com      Prod   SUBSCRIPTION_ID
3
Point at the intended subscription
az account set --subscription SUBSCRIPTION_ID
4
Verify the switch took effect
az account show --query id -o tsv
# SUBSCRIPTION_ID
✓
Safe read first — list resource groups
az group list -o table
# Name            Location    Status
# core-rg         eastus      Succeeded
!
[BILLABLE] Small scoped action — create one resource group
az group create -n RESOURCE_GROUP -l REGION
✓
Verify the action landed
az group show -n RESOURCE_GROUP --query properties.provisioningState -o tsv
# Succeeded

Troubleshooting — symptom → first check → next check

SymptomFirst checkEstablishesNext check
AuthorizationFailed / access denied on a commandaz role assignment list --assignee $(az ad signed-in-user show --query id -o tsv) --all -o tableWhether your identity holds a role that grants the action on that scope.Request the needed role on the scope, or re-run as a principal that has it.
Expired or invalid credentials, token refresh failedaz account get-access-tokenWhether the cached token is still valid for this tenant.Re-authenticate with az login (add --tenant TENANT_ID for a specific tenant).
Changes landed in the wrong placeaz account show --query id -o tsvActive subscription id vs the one you intended.az account set --subscription SUBSCRIPTION_ID, then re-verify before acting.
ResourceNotFound though the resource existsaz account list --query "[].{name:name,tenant:tenantId}" -o tableWhich tenant your context is in — the resource may live in another.az login --tenant TENANT_ID, then az account set to the right subscription.
Command errors asking for --location / regionaz configure -lWhether a default location is configured.Pass -l REGION, or set az configure --defaults location=REGION.
429 TooManyRequests / throttling from ARMRe-run with --debug and read the Retry-After response header.That the subscription/tenant hit an ARM rate limit.Back off for Retry-After seconds, batch calls, add --no-wait, and cut polling frequency.

References

az CLI 2.x (2.60+) on macOS/Linux, Microsoft Entra ID auth, public Azure (ARM) cloud.

Related sheets