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

What Does az login Do

October 27, 2026October 23, 2026 by Rajkishore

A junior engineer on one of my teams once ran a cleanup script against the wrong subscription. He had signed in days earlier, never checked which subscription was active, and the script started deleting “dev” resources in a shared environment. Nothing in the script was wrong. The problem was that nobody on the team understood what does az login do behind the scenes, or which context it leaves active.

The az login command is the front door to the Azure CLI. It proves who you are, collects the subscriptions you can reach, picks a default, and caches tokens on disk. This article walks through each of those steps, the login methods for humans and automation, and the mistakes I see most often in real projects. You will be able to sign in correctly, confirm your context, and choose a safer login method for scripts and pipelines.

Table of Contents

  • What Does az login Do Step by Step?
      • The Default Interactive Login
      • Check Your Context After az login
      • Why Context Matters for Cost and Safety
      • What Does az login Do with Your Tokens?
      • Sign Out and Clear Cached Data
    • Choose the Right az login Method
    • Device Code Login for Headless Machines
    • Service Principal Login for Automation
    • Managed Identity Login Without Secrets
      • Use az login in CI/CD Pipelines
      • Permissions After az login: RBAC
      • Test with a Non-Administrator Account
    • Monitor and Audit Sign-Ins
    • Common az login Errors and Fixes
    • Frequently Asked Questions
      • What does az login do in Azure CLI?
      • Is az login the same as Connect-AzAccount?
      • How do I know which subscription az login selected?
      • Should I use az login in a pipeline?
      • How long does an az login session last?

What Does az login Do Step by Step?

The Azure CLI is a command-line tool that talks to Azure Resource Manager, the deployment and management layer for every Azure resource. Before Resource Manager accepts a command, it needs to know who is calling. If you are new to the tool itself, start with this overview of what the Azure CLI is.

When you run az login, four things happen in order:

  1. Authentication. The CLI sends you to Microsoft Entra ID, the identity service that signs users and apps in. You enter credentials, and Entra applies its policies, including MFA and Conditional Access.
  2. Token issuance. Entra returns a short-lived access token plus a refresh token. The CLI uses the refresh token to get new access tokens silently, as described in Microsoft’s Azure CLI authentication guidance.
  3. Subscription discovery. The CLI lists every subscription your identity can see across the tenant. A subscription is the billing and governance boundary for resources.
  4. Default context. The CLI saves one subscription as your default. Every later command runs against it unless you change it.

Note what az login does not do. It does not grant permissions. It only proves identity. What you can do afterward depends on your role assignments, which I cover later.

Pro Tip: In my experience, the biggest source of “it worked on my machine” Azure mistakes is the hidden default subscription. I run az account show before any command that changes or deletes anything.

The Default Interactive Login

az login

After running the above command, it will ask to enter your Azure credentials as shown in the screenshot below.