How to Connect to Azure Tenant and Subscription via Azure CLI?

Connect to Azure Subscription:

The Azure Command-Line Interface (Azure CLI) is a cross-platform command-line tool that can be installed locally on Windows or Linux computers. You can use the Azure CLI for Windows or Linux to connect to Azure and execute administrative commands on Azure resources. 

Once CLI has been installed, Login/Connect to Azure Tenant using following command.

az login -t <tenant id>

You can find Tenant ID through Azure portal using below steps.

  • Sign in to the Azure portal.
  • Under Azure Services, select Azure Active Directory
  • Click the Overview tab and look for Tenant Information

If the CLI can open your default browser, it will do so and load an Azure sign-in page. Otherwise, open a browser page at "devicelogin" and enter the authorization code displayed in your terminal. If no web browser is available or the web browser fails to open, use device code flow with 

az login --use-device-code

Connect to subscription under which you need to create AKS Cluster.

az account set --subscription <subscription>

List of of subscriptions under current Tenants can be get through command

az account subscription list

Related Article: