title | description | ms.date | ms.topic | ms.service | ms.custom |
---|---|---|---|---|---|
Sign in with Azure CLI — Login and Authentication |
Learn the different authentication types for your Azure CLI login — sign in with Azure CLI automatically, locally, or interactively using the az login command. |
02/13/2025 |
concept-article |
azure-cli |
devx-track-azurecli |
The Azure CLI supports several authentication methods. To keep your Azure resources secure, restrict sign-in permissions for your use case.
There are four authentication options when working with the Azure CLI:
Authentication method | Advantage |
---|---|
Azure Cloud Shell | Azure Cloud Shell automatically logs you in and is the easiest way to get started. |
Sign in interactively | This option is good when learning Azure CLI commands and running the Azure CLI locally. With the az login command, you log in through your browser. Interactive login also gives you a subscription selector to automatically set your default subscription. |
Sign in with a managed identity | Managed identities provide an Azure-managed identity for applications to use when connecting to resources that support Microsoft Entra authentication. Using a managed identity eliminates the need for you to manage secrets, credentials, certificates, and keys. |
Sign in using a service principal | When you write scripts, using a service principal is the recommended authentication approach. You grant just the appropriate permissions needed to a service principal, keeping your automation secure. |
[!INCLUDE MFA]
After you sign in, CLI commands run against your default subscription. If you have multiple subscriptions, change your default subscription using az account set --subscription
.
az account set --subscription "<subscription ID or name>"
To learn more about managing Azure subscriptions, see How to manage Azure subscriptions with the Azure CLI.
[!INCLUDE refresh-token]
Note
Depending on your sign-in method, your tenant might have Conditional Access policies that restrict your access to certain resources.