Switching Azure Accounts
Switching Azure Accounts
Section titled “Switching Azure Accounts”Working with multiple Azure tenants and subscriptions requires clear commands and careful verification. This guide walks through switching contexts safely—whether you’re toggling between corporate and personal accounts, or managing multi-tenant deployments.
The 6-Step Process
Section titled “The 6-Step Process”Step 1: Logout to clear cached tokens
az logoutRemoves all cached tokens; essential when switching between accounts to avoid stale credentials.
Step 2: Login to your target account
az login# Or with explicit tenant (recommended for multi-tenant orgs):az login --tenant "your-tenant-id"Opens browser auth, or prompts for device code. Using --tenant prevents Azure from guessing your directory.
Step 3: List available subscriptions
az account list --output tableDisplays subscription ID, name, and tenant; helps you pick the right subscription.
Step 4: Set your active subscription
az account set --subscription "Your-Subscription-ID-or-Name"Activates a subscription; use either the subscription ID or friendly name.
Step 5: Configure Azure Developer CLI (if using azd)
azd env set AZURE_SUBSCRIPTION_ID <ID> -e <env-name>azd env set AZURE_LOCATION eastus -e <env-name>Syncs your CLI context to azd workflows; azd maintains its own environment file separate from az.
Step 6: Verify your active context
az account show --output tableConfirms you’re logged into the correct tenant and subscription before running any deployment.
Common Scenarios
Section titled “Common Scenarios”| Scenario | Command |
|---|---|
| Quick subscription switch (already logged in) | az account set --subscription "my-prod-sub" |
| List all my subscriptions | az account list --output table |
| Check who I am right now | az account show --output table |
| Switch tenants (multi-org) | az logout && az login --tenant "tenant-id" |
Pro Tips
Section titled “Pro Tips”- Always verify before deploying. Three seconds of
az account showsaves hours of troubleshooting wrong-tenant incidents. - Use subscription names thoughtfully. Name subscriptions descriptively (e.g.,
prod-internal-billing,client-a-dev) so typos are obvious. - Document tenant IDs. Save a local reference (plaintext or password manager) for frequently-used tenant IDs—beats hunting through Azure portal every time.