This Azure article will discuss how to log in to Azure CLI.
Table of Contents
Azure CLI login
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 with 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
- The URL or the name that is associated with the service principal.
- You need the X509 certificate or the service principal password.
- 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>
Azure CLI login with 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>
Azure CLI login with 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
Conclusion
So, In this article, we discussed all about Azure CLI login process. Thanks for taking the time to read this article !!!

I am Rajkishore, and I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machine, 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.