The az login command is part of the az command-line client for Microsoft Azure, which is the official Command-Line Interface (CLI) provided by Microsoft for managing Azure resources and services.
The az login command is used to authenticate and log in to the Azure cloud platform. Here’s an overview of its functionality:
- Authentication: The az login command initiates the authentication process for accessing Azure resources and services through the CLI. When you run this command, it opens a browser window or displays a device code that you can use to authenticate with your Azure account.
- Interactive Login: With the az login command, you can perform an interactive login, which allows you to authenticate by providing your Azure account credentials. You’ll be prompted to enter your username and password, and once authenticated, you’ll have access to your Azure subscriptions and resources.
- Service Principal Login: In addition to interactive login, the az login command also supports service principal login. Service principals are Azure Active Directory (AAD) identities that can be used to authenticate applications and scripts. By providing the necessary authentication parameters, such as the tenant ID, client ID, and client secret, you can log in using a service principal.
- Multiple Account Support: Azure CLI allows you to work with multiple Azure subscriptions and accounts. When you log in using the az login command, you can switch between different Azure accounts and subscriptions to perform operations on their associated resources. This is particularly useful for managing resources across different environments or organizations.
- Persistent Authentication: After successfully logging in with the az login command, the Azure CLI stores the authentication token locally. This allows you to perform subsequent operations without needing to authenticate again, unless the token expires or you explicitly sign out.
The az login command is a fundamental command for accessing and managing Azure resources through the Azure CLI. It establishes the authentication context and grants you access to your Azure subscriptions and resources, enabling you to perform various operations such as resource provisioning, configuration, and management.
az login Command Examples
1. Log in interactively:
# az login
2. Log in with a service principal using a client secret:
# az login --service-principal --username http://azure-cli-service-principal --passsword secret --tenant someone.onmicrosoft.com
3. Log in with a service principal using a client certificate:
# az login --service-principal --username http://azure-cli-service-principal --password /path/to/cert.pem --tenant someone.onmicrosoft.com
4. Log in using a VM’s system assigned identity:
# az login --identity
5. Log in using a VM’s user assigned identity:
# az login --identity --username /subscriptions/subscription_id/resourcegroups/my_rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my_id