Setting Up Azure CLI on Ubuntu Linux

Setting Up Azure CLI on Ubuntu Linux

Azure has a great web interface called azure portal for performing all the functions. But if you prefer command line tools over graphical user interface, you can make use of azure command line interface to manage all azure resources.

Setting up Azure CLI on Ubuntu

This tutorial will guide you for setting up azure cli on Ubuntu Linux systems.

For this setup, we have used the following versions of the components,

  1. Ubuntu 24.04
  2. Sudo/root permission to execute the commands (Local workstation)
  3. Azure user credentials

Step 1: Install the required packages to install the Azure CLI

Use the following command to install the packages

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release

Step 2: Install the singing Key

The official signing key will help verify the package

sudo mkdir -p /etc/apt/keyrings
curl -sLS https://packages.microsoft.com/keys/microsoft.asc |
  gpg --dearmor | sudo tee /etc/apt/keyrings/microsoft.gpg > /dev/null
sudo chmod go+r /etc/apt/keyrings/microsoft.gpg

Step 3: Add the Azure CLI Repository

Use the following command to add the repo files on the machine where you want to install the Azure CLI

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.sources

Step 4: Install the Azure CLI Package

Use the following command to install the Azure CLI on the Ubuntu machine

sudo apt-get update
sudo apt-get install azure-cli

Step 5: Verify Installation

Once installed, verify the installation using the following command.

az version

You will get a similar output

The output of the azure cli version

Configuring CLI with Azure Subscription

To connect to your Azure subscription, you should configure your CLI for authentication. You can do this by executing the following command.

az login

This will open an interactive web page and prompt you to provide your Azure cloud user credentials, such as Mail ID and the Password.

Once you are done with it, you will see the confirmation in your command line as shown below.

💡
If you want to authenticate the Azure CLI with the Azure Service Principle refer this blog --> Authenticate Azure CLI Using Service Principal

Adding Subscriptions

If you have different subscriptions with your Azure account, you can add a specific subscription for the CLI. To do that, get the subscription name using the following command.

az account list --output table

Add then, you can set a specific subscription using the following command.

az account set --subscription "<subscription-name-or-id>"

Conclusion

The document covered the installation of the Azure CLI on an Ubuntu machine and authenticating with the user credentials.

About the author
devopscube

devopscube

Since 2014, we're a thriving DevOps community dedicated to helping DevOps Engineers grow with high-quality, in-depth articles, comprehensive learning paths, expert insights, and practical resources.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to DevOpsCube – Easy DevOps, SRE Guides & Reviews.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.