Skip to content
Azure Lessons
Azure Lessons
  • Home
  • AWS
  • Azure
    • Azure Virtual Machine
    • Azure Active Directory
    • Azure CLI
    • Azure CLI Commands List
    • Azure Cognitive Services
    • Azure Cosmos DB
    • Azure DevOps
    • Azure Functions
    • Azure PowerShell Commands
    • Azure Sentinel
    • Azure SQL
    • Azure Storage
    • Azure Synapse
  • Blogs
  • FREE EBOOK

How to login to Azure CLI

February 18, 2025 by Rajkishore

This Azure article will discuss how to login Azure CLI.

Table of Contents

  • How to login to Azure CLI
    • Approach-1 Using Username and Password
    • Approach-2 Using a different tenant
    • Approach-3 Using managed identity
    • Approach-4 Using service principal

How to login to Azure CLI

To login to Azure CLI, follow the simple approaches below. Let us discuss all the approaches individually.

Approach-1 Using Username and Password

While working with the Azure CLI, you can sign in with the help of the Browser with the Az login command. you can use the below PowerShell cmdlet

az login

Once you execute the above Azure CLI command, enter your Account credentials to log in. But with the command, you can also provide your credentials to log in to the Azure CLI. you can use the az login command with the username and password below.

az login -u <username> -p <password>

You don’t want to display the password openly. To avoid this scenario, you can use the PowerShell cmdlet like below

$Cred = Get-Credential -UserName <Enter your username>
az login -u $Cred.UserName -p $Cred.GetNetworkCredential().Password

Once you execute the above command, you will get something like the below

Azure CLI login

Approach-2 Using a different tenant

You can also sign in with a different tenant. You need to specify the tenant name with the â€“tenant parameter.

az login --tenant <tenant>
az login --tenant 5d9d690a-0310-474d-ae8b-42df2d549228

After executing the above command, I got the expected output as shown below.

az login

Now, click on the above link as highlighted in the above screenshot and then enter the code as mentioned above.

azure cli login using service principal
azure cli login managed identity
azure cli login service principal

Approach-3 Using managed identity

Another way to log in is to sign in with a managed identity. Below is the cmdlet you can use to sign in with a managed identity.

az login --identity

After executing the above command, I got the expected output as shown below.

{
    "environmentName": "AzureCloud",
    "homeTenantId": "5d9d690a-0310-474d-ae8b-42df2d549228",
    "id": "1cdf4300-dee5-4518-9c9c-feaa72a5cbd1",
    "isDefault": true,
    "managedByTenants": [],
    "name": "Visual Studio Enterprise",
    "state": "Enabled",
    "tenantId": "5d9d690a-0310-474d-ae8b-42df2d549228",
    "user": {
      "cloudShellID": true,
      "name": "live.com#fewlinesxyz@hotmail.com",
      "type": "user"
    }
  }

You can check out the same output in the below screenshot.

how to login azure cli

Approach-4 Using service principal

You can also sign in with the service principal. To give you a glance at the service principal. Service Principals are the accounts not tied to any specific user that can have permissions on them assigned via predefined roles. Using the service principal to log in is one of the most secure ways.

There are a few things that you need to sign in with a service principal

  1. The URL or the name that is associated with the service principal.
  2. You need the X509 certificate or the service principal password.
  3. You need the tenant that is associated with the service principal.

The PowerShell cmdlet will be like below

az login --service-principal -u <app-url> -p <password-or-cert> --tenant <tenant>

If you don’t want to display the details to the outer world, you can use the PowerShell cmdlet below

$Cred = Get-Credential -UserName <app-url>
az login --service-principal -u $Cred.UserName -p $Cred.GetNetworkCredential().Password --tenant <tenant>

Conclusion

So, In this article, we discussed all about Azure CLI login process. Thanks for taking the time to read this article !!!

Microsoft Azure
Rajkishore

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.

Microsoft 365 vs Azure
Microsoft entra self-service password reset
Subscribe To Our YouTube Channel Subscribe to AzureLessons YouTube Channel

Recent Posts

  • Azure synapse Analytics Tutorial
  • Azure VM Backup Pricing
  • Azure VM
  • What Is Edge Location In AWS
  • DP-300 Certification
  • About Us
  • Contact Us
  • Privacy Policy
  • Sitemap
© 2026 Azure Lessons
Azure
Virtual
Machine
By: Rajkishore
Azure Consultant
PDF

Free 25+ page PDF

Download free Azure Virtual Machine PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!

No spam, ever. You will also get new Azure tutorials by email. Unsubscribe any time. Privacy policy

Check your inbox

Your Azure Virtual Machine PDF is on its way to . Can't find it in a few minutes? Look in your Promotions or Spam folder.