Azure: installing the Azure CLI on Ubuntu

Managing resources in Azure from the command line can be done natively from Ubuntu using the Azure CLI.  First, add the prerequisite packages.

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

Then install the Microsoft signing key and add the custom repository.

curl -sL https://packages.microsoft.com/keys/microsoft.asc |
gpg --dearmor |
sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null

echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" |
sudo tee /etc/apt/sources.list.d/azure-cli.list

Finally, install the Azure CLI.

sudo apt-get update
sudo apt-get install azure-cli -y
az --version

If on a Linux desktop with a GUI browser, this command will spawn a browser that establishes authentication.

# if on a desktop GUI
az login

# prove authentication
az group list -o table

However, if you are on a headless server then you will need to generate a code that can then be used from a device that does have browser access (https://aka.ms/devicelogin or https://microsoft.com/devicelogin).

# force authentication via code
az login --use-device-code

# prove authentication
az group list -o table

 

REFERENCES

Microsoft, Azure CLI installation using apt

Azure portal