Introduction
Microsoft Azure CLI is an essential command-line tool for cloud administrators, DevOps engineers, database administrators and IT infrastructure professionals who manage Microsoft Azure environments.
Whether you're deploying Azure Virtual Machines, managing Azure Storage, automating infrastructure operations or integrating Azure services into CI/CD pipelines, Azure CLI provides a powerful and scriptable interface.
However, installing Azure CLI on Ubuntu Linux can sometimes be challenging, particularly when Microsoft repository URLs are configured incorrectly, GPG signing keys are invalid or package dependencies cannot be resolved.
In this technical guide, we explain how to install Azure CLI on Ubuntu 22.04 LTS and Ubuntu 24.04 LTS, troubleshoot common installation failures and configure secure authentication using Microsoft Entra ID and Azure Managed Identities.
1. What Is Microsoft Azure CLI?
Azure CLI is Microsoft's cross-platform command-line interface for managing Azure resources.
It enables administrators to interact with Azure services directly from Linux terminals, Windows PowerShell, macOS and automation environments.
Common use cases include:
Azure Virtual Machines: Create, start, stop, resize and manage VMs.
Azure Storage: Manage storage accounts, blob containers and files.
Azure Networking: Configure virtual networks, subnets, NSGs and network interfaces.
Azure Database Services: Manage Azure SQL Database and other supported database resources.
Azure Kubernetes Service (AKS): Manage Kubernetes clusters and retrieve cluster credentials.
Infrastructure Automation: Integrate Azure management tasks with Bash scripts, GitHub Actions and Azure DevOps.
Security and Identity: Manage supported Azure RBAC operations and authenticate using Managed Identities.
Azure CLI is particularly useful when managing multiple subscriptions or automating repetitive infrastructure administration tasks.
2. Prerequisites
Before installing Azure CLI, ensure that your Linux environment meets the following requirements:
Ubuntu 22.04 LTS or Ubuntu 24.04 LTS.
An account with
sudoprivileges.Internet connectivity to Microsoft's package repositories.
A supported system architecture.
Access to an Azure subscription for testing authentication and resource management.
Check your Ubuntu version:
cat /etc/os-releaseFor Ubuntu 22.04, the output will include:
VERSION_ID="22.04"
VERSION_CODENAME=jammyFor Ubuntu 24.04:
VERSION_ID="24.04"
VERSION_CODENAME=nobleThe distribution codename is important because Microsoft's repository configuration uses the appropriate Ubuntu release name.
3. Install Required Packages
First, update the available package information:
sudo apt-get updateInstall the dependencies required to configure the Microsoft repository:
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-releaseThese packages provide the necessary capabilities for downloading repository keys, validating package signatures and identifying the Linux distribution.
4. Configure the Microsoft Signing Key
Ubuntu uses repository signing keys to verify the authenticity of packages.
An incorrect GPG key configuration can prevent Azure CLI from being installed.
Create the APT keyring directory:
sudo mkdir -p /etc/apt/keyringsDownload the official Microsoft signing key:
curl -fsSL \
https://packages.microsoft.com/keys/microsoft.asc \
-o /tmp/microsoft.ascInspect the downloaded key:
gpg --show-keys /tmp/microsoft.ascConvert the key into the format used by APT:
gpg --dearmor < /tmp/microsoft.asc | \
sudo tee /etc/apt/keyrings/microsoft.gpg > /dev/nullConfigure the required permissions:
sudo chmod 644 /etc/apt/keyrings/microsoft.gpgThis ensures that APT can read the Microsoft signing key when validating repository metadata.
Security recommendation: Always obtain signing keys from official Microsoft sources and validate downloaded content before adding it to a production Linux environment.
5. Add the Official Azure CLI Repository
Azure CLI packages are distributed through Microsoft's dedicated package repository.
The correct repository endpoint is:
https://packages.microsoft.com/repos/azure-cli/Identify the Ubuntu codename:
lsb_release -csThen configure the Azure CLI repository:
AZ_DIST=$(lsb_release -cs)
echo "Types: deb
URIs: https://packages.microsoft.com/repos/azure-cli/
Suites: ${AZ_DIST}
Components: main
Architectures: $(dpkg --print-architecture)
Signed-by: /etc/apt/keyrings/microsoft.gpg" | \
sudo tee /etc/apt/sources.list.d/azure-cli.sourcesThis repository configuration supports both Ubuntu 22.04 and Ubuntu 24.04 by automatically selecting the appropriate distribution codename.
6. Install Microsoft Azure CLI
Update the APT repository information:
sudo apt-get updateVerify that the Azure CLI package is available:
apt-cache policy azure-cliThe output should identify an installation candidate from Microsoft's repository.
Install Azure CLI:
sudo apt-get install -y azure-cliOnce the installation finishes, verify the installed version:
az versionYou can also run:
az --versionA successful response displays the installed Azure CLI version and related components.
7. Troubleshooting Common Azure CLI Installation Errors
During Azure CLI installation, Linux administrators may encounter several errors caused by incorrect URLs, repository configuration issues or missing signing keys.
Error 1: Bash Syntax Error — Unexpected Token
Error message:
bash: line 1: syntax error near unexpected token `newline'
bash: line 1: `<!doctype html>'Why this happens
This error typically occurs when a curl command downloads an HTML document instead of an executable Bash script.
For example, executing a generic website URL through Bash can result in an HTML page being interpreted as shell commands.
Resolution
Download scripts only from documented installation URLs. For production systems, we recommend configuring the Microsoft APT repository manually using the steps above, which provides better visibility into installation changes.
Avoid blindly executing downloaded scripts without inspecting their contents.
Error 2: No Valid OpenPGP Data Found
Error message:
gpg: no valid OpenPGP data found.Why this happens
The URL used to download the Microsoft signing key returned content that was not a valid OpenPGP key, or the download failed.
Resolution
Use the correct Microsoft key URL:
curl -fsSL \
https://packages.microsoft.com/keys/microsoft.asc \
-o /tmp/microsoft.ascValidate the key:
gpg --show-keys /tmp/microsoft.ascIf the key is valid, convert and install it as described earlier.
If validation fails, investigate proxy configuration, network access or TLS certificate errors before continuing.
Error 3: Repository Does Not Have a Release File
Error message:
404 Not Found
E: The repository does not have a Release file.Why this happens
The configured repository URL is invalid or does not contain the required package metadata for the selected distribution.
For example, using a general Microsoft website as an APT repository will not work.
Resolution
Inspect the repository configuration:
cat /etc/apt/sources.list.d/azure-cli.sourcesEnsure it references:
https://packages.microsoft.com/repos/azure-cli/Remove an incorrectly created Azure CLI repository file if necessary:
sudo rm -f /etc/apt/sources.list.d/azure-cli.listOnly remove files confirmed to belong to the incorrect configuration.
Recreate the correct repository configuration and execute:
sudo apt-get updateError 4: Unable to Locate Package azure-cli
Error message:
E: Unable to locate package azure-cliWhy this happens
APT cannot locate the azure-cli package because the Microsoft Azure CLI repository is missing, disabled or incorrectly configured.
Resolution
Check package availability:
apt-cache policy azure-cliVerify that the correct repository file exists:
ls -l /etc/apt/sources.list.d/After correcting the repository, run:
sudo apt-get update
sudo apt-get install -y azure-cliError 5: Connection or Certificate Validation Failure
Enterprise Linux systems may access the internet through firewalls, proxies or restricted outbound network configurations.
These controls can prevent APT from downloading Microsoft repository metadata.
Test connectivity:
curl -I https://packages.microsoft.comYou can also examine verbose connection details:
curl -vI https://packages.microsoft.comIf the connection fails, verify DNS resolution, HTTPS outbound access, proxy settings and the server's trusted certificate authorities.
Do not disable certificate verification as a workaround.
8. Authenticate Azure CLI to Microsoft Azure
After Azure CLI has been installed, the next step is authentication.
Method 1: Interactive Login
For a Linux server with no graphical browser, use device-code authentication:
az login --use-device-codeThe terminal displays authentication instructions and a verification code.
Open the indicated Microsoft authentication page on another device, enter the code and complete authentication.
List subscriptions available to the authenticated account:
az account list -o tableSelect the required subscription:
az account set --subscription "<subscription-id>"Verify the active subscription:
az account show -o tableThis approach is suitable for interactive administrative tasks.
Method 2: Azure Managed Identity
For Azure-hosted virtual machines, Managed Identity is generally the preferred authentication method for automated workloads.
A Managed Identity allows supported Azure resources to authenticate to Azure services without embedding credentials in application code or scripts.
First, enable a system-assigned or user-assigned Managed Identity on the Azure VM and assign only the required Azure RBAC permissions.
Then authenticate:
az login --identityConfirm the current account context:
az account show -o tableFor a user-assigned Managed Identity, specify the identity client ID:
az login --identity --client-id "<client-id>"Best practice: Use Managed Identity for Azure-hosted automation wherever possible and follow least-privilege access principles.
9. Useful Azure CLI Commands for Linux Administrators
Once authenticated, Azure CLI can help administrators perform routine infrastructure management tasks.
| Task | Azure CLI command |
|---|---|
| Display CLI version | az version |
| List Azure subscriptions | az account list -o table |
| Show active subscription | az account show -o table |
| List resource groups | az group list -o table |
| List virtual machines | az vm list -d -o table |
| List storage accounts | az storage account list -o table |
| List virtual networks | az network vnet list -o table |
| List Azure SQL servers | az sql server list -o table |
| List AKS clusters | az aks list -o table |
| Log out | az logout |
These commands help administrators rapidly inspect Azure resources without navigating through multiple Azure Portal screens.
Actual command results depend on subscription access and the permissions assigned to the authenticated identity.
10. How to Update Azure CLI on Ubuntu
Microsoft regularly releases updates to Azure CLI to introduce new capabilities, improve compatibility and address defects.
To update the Azure CLI package without upgrading every installed system package:
sudo apt-get update
sudo apt-get install --only-upgrade -y azure-cliVerify the updated version:
az versionAlternatively, Azure CLI provides:
az upgradeFor production servers, administrators should review release notes and extension compatibility before performing upgrades.
Consider testing upgrades in development or staging environments first, particularly when Azure CLI is part of scheduled operational scripts or deployment pipelines.
11. Azure CLI Security Best Practices
Installing Azure CLI is only the beginning. Secure configuration and ongoing maintenance are equally important.
We recommend the following operational practices:
Use Managed Identity for automation: Avoid storing service principal secrets or user credentials in Bash scripts.
Apply least-privilege permissions: Grant identities only the required Azure RBAC roles.
Use trusted repositories: Install Azure CLI from Microsoft's official package sources.
Keep Azure CLI updated: Review supported versions and apply security and compatibility updates.
Protect authentication information: Do not expose tokens, subscription-sensitive information or credentials in shared logs.
Avoid running administrative scripts as root unnecessarily: Use appropriately privileged accounts and limit
sudooperations.Monitor automated operations: Implement logging, error handling and alerting for critical Azure scripts.
Test changes before production deployment: Validate resource permissions and scripts in non-production environments.
These practices help organisations reduce security risks while maintaining reliable cloud operations.
12. How Onsys Technologies Can Help
Managing Azure infrastructure requires more than installing command-line tools.
Organisations must also ensure that their cloud environments are secure, reliable, cost-effective and supported by consistent operational processes.
At Onsys Technologies, we assist businesses with Microsoft Azure administration, cloud infrastructure engineering and managed IT operations.
Our capabilities include:
Microsoft Azure architecture, deployment and administration.
Azure infrastructure automation and operational scripting.
Linux and Windows Server management.
Azure Virtual Machines and networking.
Azure SQL Database and SQL Managed Instance administration.
Azure migration, backup and disaster recovery.
Azure monitoring, troubleshooting and performance optimisation.
Managed cloud and database support services.
Whether you're configuring a new Azure environment, troubleshooting Linux infrastructure or improving cloud automation, Onsys Technologies can help your organisation manage Azure more effectively.
Contact Onsys Technologies
Website: https://www.onsys.com.au
Explore our cloud infrastructure and managed IT services to discuss your Azure administration and support requirements.
Conclusion
Installing Azure CLI on Ubuntu 22.04 or 24.04 LTS is straightforward when the correct Microsoft repository and signing key are configured.
Most installation failures involving invalid GPG keys, repository errors or missing packages are caused by incorrect repository URLs or incomplete installation steps.
By using the official Microsoft package repository, validating the installation and implementing secure authentication through Microsoft Entra ID or Managed Identity, Linux administrators can establish a reliable foundation for managing and automating Microsoft Azure resources.
For production infrastructure, always combine Azure CLI automation with appropriate access controls, change management, monitoring and regular maintenance.
Technical Reference
Microsoft Learn — Install the Azure CLI on Linux
https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux
Published by Onsys Technologies — Microsoft Azure, Cloud Infrastructure and Database Administration Specialists.

