هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
You log in once with your Microsoft Entra ID account. The CLI keeps a token and sends every command as an API call to Azure Resource Manager. Every resource lives in a subscription and a resource group.
| Item | Value |
|---|---|
| Package | azure-cli (from packages.microsoft.com) |
| Program | az (Python inside, installed in /opt/az/) |
| Config and tokens | ~/.azure/ (config, token cache) |
| Extensions | ~/.azure/cliextensions/ |
| Environment | AZURE_CONFIG_DIR, AZURE_CORE_OUTPUT, REQUESTS_CA_BUNDLE |
| Network | HTTPS (443) to login.microsoftonline.com and management.azure.com |
Install on RHEL, Rocky, Alma and Fedora
Import the Microsoft key, add the repository package for your RHEL major version (9 or 10) and install:
rpm --import https://packages.microsoft.com/keys/microsoft.asc
dnf -y install https://packages.microsoft.com/config/rhel/9.0/packages-microsoft-prod.rpm
dnf -y install azure-cli
az versionOn RHEL 10 use …/config/rhel/10/packages-microsoft-prod.rpm.
Install on Ubuntu and Debian
apt-get update
apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
mkdir -p /etc/apt/keyrings
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /etc/apt/keyrings/microsoft.gpg
chmod go+r /etc/apt/keyrings/microsoft.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list
apt-get update
apt-get install -y azure-cli
az versionMicrosoft also has a one-line script (curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash). It does the same steps; the manual way shows you what changes.
First configuration: log in and choose the subscription
Log in. On a server without a browser use the device code:
az login
az login --use-device-code
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ABCD-EFGH to authenticate.Check where you are, and choose the right subscription — this is the most important step:
az account list -o table
az account set --subscription "Prod-Shop"
az account show --query '{name:name, id:id, user:user.name}' -o tableSet defaults so you type less, and a readable output:
az config set core.output=table
az config set defaults.group=rg-shop-prod defaults.location=westeurope
az config set core.collect_telemetry=false
echo 'source /etc/bash_completion.d/azure-cli' >> ~/.bashrc| Setting | Why |
|---|---|
az account set | Every command goes to this subscription. A wrong one = changes in the wrong place. |
core.output=table | Easy to read; use -o json or -o tsv in scripts. |
defaults.group, defaults.location | No -g and -l on every command. |
core.collect_telemetry=false | No usage data sent to Microsoft. |
ملاحظة
Scripts and pipelines do not use your personal login. Use a managed identity on Azure VMs (az login --identity), or workload identity federation (OIDC) in GitHub Actions and Azure DevOps — no client secrets to store or rotate.
Daily use: the commands and the real uses
Resource groups and resources:
az group list
az group create -n rg-lab -l westeurope --tags owner=ops env=lab
az resource list -g rg-shop-prod
az group delete -n rg-lab --yes --no-waitVirtual machines:
az vm list -d --query "[].{name:name, state:powerState, ip:privateIps}"
az vm create -g rg-lab -n vm1 --image Ubuntu2404 --size Standard_B2s --admin-username azureuser --generate-ssh-keys --public-ip-address ""
az vm stop -g rg-lab -n vm1
az vm deallocate -g rg-lab -n vm1Storage, AKS, Key Vault and identity:
az storage account list --query "[].{name:name, tls:minimumTlsVersion, public:allowBlobPublicAccess}"
az aks get-credentials -g rg-aks -n aks-prod
az keyvault secret show --vault-name kv-shop --name db-password --query value -o tsv
az role assignment list --assignee alice@example.com --all
az extension add --name sshReal uses at work:
- Build and check resources fast; reports with
--query(JMESPath) and-o tsvin scripts. - Get the kubeconfig of AKS for
kubectl; read secrets from Key Vault in pipelines. - Audit: public storage accounts, open NSG rules, role assignments.
في العمل
vm stop keeps paying for the compute; vm deallocate stops the costs (only the disks cost money).
Make it safe
Security checklist:
- MFA (Conditional Access) for every human account.
- Least privilege with Azure RBAC; give roles to groups, at the resource group, not the subscription.
- Managed identities and OIDC instead of service principal secrets; if you must use a secret, short expiry and Key Vault.
- Check the subscription before every change:
az account show. ~/.azure/holds your tokens: never copy it to shared machines;az logouton shared hosts.- Keep
azupdated (az upgrade) — old versions miss security fixes.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
Please run 'az login' to setup account | No login, or the token expired. | az login (or --use-device-code). |
AADSTS50076 / AADSTS50079 | MFA or Conditional Access is required. | Log in interactively; for a tenant: az login --tenant TENANT_ID. |
The subscription '…' could not be found | Wrong tenant or no access. | az account list --all; log in to the right tenant. |
AuthorizationFailed … does not have authorization to perform action | Your role is too small at this scope. | az role assignment list --assignee ME --all; ask for a role. |
| Resources "not found" | Wrong subscription or resource group. | az account show; az config get defaults. |
SSL: CERTIFICATE_VERIFY_FAILED behind a proxy | The company proxy CA is unknown. | export REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt after adding the CA. |
az: 'xyz' is not in the 'az' command group | The command needs an extension. | az extension add --name xyz (or az config set extension.use_dynamic_install=yes_without_prompt). |
Next steps
- Quick how-tos: Log in and choose a subscription, Get the AKS kubeconfig, Deploy from GitHub Actions with OIDC, Create a VM, Find costly resources, Lock a resource group, Private storage account, Query logs with KQL.
- Command page: az — every command group and option.
- Learn Azure for the exam: AZ-104 summary, AZ-104 with Manara.
- Practise: Lab: a locked-down storage account.
- The Azure CLI at work: Manage Azure, Azure CLI in DevOps.
- Build Azure with code: Install and set up Terraform. Use AKS: Install and set up kubectl.
1What is the first thing to check before you change resources with az?
The subscription: az account show.
2How should a pipeline log in to Azure without a stored secret?
With workload identity federation (OIDC), or a managed identity when it runs on Azure.