Azure CLI
The Azure CLI is a cross-platform command-line tool for managing Azure resources. This guide covers 2025 best practices, installation on Linux/WSL/NixOS, real-life DevOps scenarios, LLM integration, a
2025 Best Practices
Always use the latest Azure CLI version (
az upgrade
)Use service principals or managed identities for automation, not personal accounts
Store secrets in Azure Key Vault, not in scripts or environment variables
Use
--output json
for scripting and automationLeverage
az account set
and named profiles for multi-tenant/multi-subscription workUse
.envrc
and direnv for environment isolationAutomate with LLMs (GitHub Copilot, Claude) for repeatable workflows
Enable CLI telemetry only if required for troubleshooting
Installation
Linux (Ubuntu/Debian/Fedora/Arch)
NixOS
Add to your configuration.nix
:
Then rebuild:
Windows Subsystem for Linux (WSL)
Follow the Linux instructions inside your WSL terminal. For persistent PATH, add to ~/.bashrc
or ~/.zshrc
:
Docker/Podman
Windows
Authentication & Profile Management
Login
List and Set Subscriptions
Named Profiles (2025+)
Using .envrc and direnv for Environment Isolation
Create a .envrc
in your project directory:
Enable direnv:
Real-Life Scenarios
1. Provision a VM with Terraform and az CLI
2. Automate AKS Authentication and kubectl Context
3. Use az CLI with GitHub Copilot or Claude
Use Copilot/Claude to generate az CLI scripts for resource automation:
Review, test, and version-control generated scripts.
4. Multi-Cloud/Hybrid Automation
Use az CLI in GitHub Actions, Azure Pipelines, or GitLab CI/CD for IaC and deployment.
Example GitHub Actions step:
Authenticating Against AKS and Other Services
AKS
Azure Container Registry (ACR)
Azure Key Vault
Useful Resources
Last updated