Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 3.1 KB

authenticate-azure-cli.md

File metadata and controls

51 lines (35 loc) · 3.1 KB
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

Authenticate to Azure using Azure CLI

The Azure CLI supports several authentication methods. To keep your Azure resources secure, restrict sign-in permissions for your use case.

Sign into Azure with Azure CLI

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.

Multi-factor authentication (MFA)

[!INCLUDE MFA]

Find or change your current subscription

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.

Refresh tokens

[!INCLUDE refresh-token]

Note

Depending on your sign-in method, your tenant might have Conditional Access policies that restrict your access to certain resources.

See also