Setting Up Azure CLI on Ubuntu Linux

azure cli ubuntu setup

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.

Azure cli need nodejs runtime for performing the cli operations. Execute th following commands for installing azure cli using npm.

sudo apt-get install nodejs-legacy
sudo apt-get install npm
sudo npm install -g azure-cli

If you would like to install it from source, you can use the following commands.

git clone https://github.com/Azure/azure-xplat-cli.git
cd ./azure-xplat-cli
npm install
bin/azure 

Verify Installation:

Once installed, verify the installation using the following command.

azure help

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.

azure login

The above command will output an url and code to get authenticated via browser. Open the url in a browser, enter the code and login to your azure account. Once you are done with it, you will see the confirmation in your command line as shown below.

devops@opsguy:~# azure login
info:    Executing command login
/info:    To sign in, use a web browser to open the page https://aka.ms/devicelogin. Enter the code SDFHRGF to authenticate. If you're signing in as an Azure AD application, use the --username and --password parameters.
|info:    Added subscription Free Trial
info:    Setting subscription "Free Trial" as default
+
info:    login command OK
devops@opsguy:~#

Adding Subscriptions

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

azure account list

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

azure account set your-subscription

Authentication Using Publishsettings File

You can also use the publishsetting file to authenticate against azure. Execute the following command to download the publishsetting file.

azure account download

You will get the below output.

mike@opsguy:~/test$ azure account download
info:    Executing command account download
info:    Launching browser to http://go.microsoft.com/fwlink/?LinkId=345334
mike@opsguy:~/test$

Go the link specified in your output and download the file. Once downloaded, execute the following command to import the file.

azure import <downloaded-publish-setting-file>  
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like