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 context
az account show -o tableActive subscription, tenant, and signed-in user — run this before any change.Sign in
az loginBrowser auth; headless hosts use az login --use-device-code.Switch subscription
az account set --subscription SUBSCRIPTION_IDPoint every later command at the intended subscription.List resources
az resource list -g RESOURCE_GROUP -o tableWhat exists in a group; drop -g to span the whole subscription.Set default region + group
az configure --defaults location=REGION group=RESOURCE_GROUPAzure has no global region; defaults save repeating -l / -g.Authenticate → confirm context → read → scoped action → verify
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
| Task | Command | Check |
|---|---|---|
| Sign in interactively | az login | Returns a JSON array of subscriptions; az account show lists the expected user. |
| Sign in on a headless / remote host | az login --use-device-code | Device code is accepted in the browser; subscriptions are returned. |
| List subscriptions you can see | az account list -o table | Target subscription appears; IsDefault marks the active one. |
| Confirm the active identity and subscription | az account show --query "{user:user.name, sub:name, id:id}" -o table | User and subscription id match what you intend to operate on. |
| Switch to the intended subscription | az account set --subscription SUBSCRIPTION_ID | az account show --query id -o tsv now returns SUBSCRIPTION_ID. |
| Set a default region and resource group | az configure --defaults location=REGION group=RESOURCE_GROUP | az configure -l lists location and group defaults. |
| List resource groups | az group list -o table | Expected RESOURCE_GROUP is present with its location. |
| List resources inside a group | az resource list -g RESOURCE_GROUP -o table | Expected resources show with their types and locations. |
| List VMs with power state | az vm list -d -o table | PowerState column shows running/stopped per VM. |
| Tail App Service logs | az webapp log tail -g RESOURCE_GROUP -n APP_NAME | Live log lines stream; Ctrl-C to stop. |
| Pull AKS cluster credentials | az aks get-credentials -g RESOURCE_GROUP -n CLUSTER | kubectl config current-context points at CLUSTER. |
| List role assignments for a principal | az role assignment list --assignee PRINCIPAL_ID --all -o table | Expected roles and scopes are listed for that principal. |
| [BILLABLE] Create a resource group | az group create -n RESOURCE_GROUP -l REGION | provisioningState is Succeeded; appears in az group list. |
| [CHANGES ACCESS] Assign a role at a scope | az role assignment create --assignee PRINCIPAL_ID --role Reader --scope SCOPE | New 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_ID3
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
# SucceededTroubleshooting — symptom → first check → next check
| Symptom | First check | Establishes | Next check |
|---|---|---|---|
| AuthorizationFailed / access denied on a command | az role assignment list --assignee $(az ad signed-in-user show --query id -o tsv) --all -o table | Whether 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 failed | az account get-access-token | Whether 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 place | az account show --query id -o tsv | Active subscription id vs the one you intended. | az account set --subscription SUBSCRIPTION_ID, then re-verify before acting. |
| ResourceNotFound though the resource exists | az account list --query "[].{name:name,tenant:tenantId}" -o table | Which 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 / region | az configure -l | Whether a default location is configured. | Pass -l REGION, or set az configure --defaults location=REGION. |
| 429 TooManyRequests / throttling from ARM | Re-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
- Sign in with the Azure CLI (az login)learn.microsoft.com
- az account command referencelearn.microsoft.com
- Manage role assignments with Azure CLIlearn.microsoft.com
- Azure CLI reference indexlearn.microsoft.com
- ARM request limits and throttlinglearn.microsoft.com
az CLI 2.x (2.60+) on macOS/Linux, Microsoft Entra ID auth, public Azure (ARM) cloud.