Safeguard
Security Guides•

Which Azure CLI sign in method should you use?

Interactive login for your laptop, a service principal for scripts, a managed identity on Azure. Microsoft also requires MFA for user logins in the CLI.

Safeguard Security Team
3 min read

Sign in interactively with az login on your own laptop, use a service principal for scripts, and use a managed identity for code running on Azure. Microsoft's documentation also says it started requiring multifactor authentication for user identities in Azure CLI from September 2025, so password based script logins need to move.

The four options

Microsoft lists four ways to authenticate the Azure CLI:

MethodBest forNotes
Azure Cloud ShellGetting startedLogs you in automatically
Interactive sign inLearning and local workBrowser based; picks a default subscription
Managed identityApplications on AzureRemoves the need to manage secrets, credentials, certificates and keys
Service principalScripts and automationDocumented as the recommended approach for scripts

The documentation also says to restrict sign in permissions for your use case, which means granting only what the task needs.

What gets stored on a laptop

When you sign in with a user account, the CLI generates and stores an authentication refresh token. Access tokens are short lived, and the refresh token is used to get new ones. A refresh token is a longer lived secret, so treat the machine and its profile directory accordingly. The command az account get-access-token prints a live access token, so avoid pasting that output into tickets or chats.

The MFA change

The docs state that starting September 2025 Microsoft requires MFA for Azure CLI and other command line tools, and that this applies to Microsoft Entra ID user identities but not to workload identities such as service principals and managed identities. If a pipeline or script logs in with a username and password, the documentation says to migrate it to a workload identity.

Decision guide

  1. Working by hand on your own machine: interactive login with MFA.
  2. A script on your laptop that you run often: still prefer interactive login, or a service principal scoped to one resource group.
  3. CI or scheduled jobs: a workload identity, with short lived credentials if your CI supports federation. See GitHub Actions OIDC for AWS without access keys for the same pattern on another cloud.
  4. Code running on Azure: a managed identity. See system assigned or user assigned managed identity.

Steps to tidy an existing setup

  1. Run az account list and az account show to see what is signed in.
  2. Sign out of profiles you no longer use with az logout.
  3. Search scripts for az login calls with a username and password and plan their replacement.
  4. Give each service principal the least role on the smallest scope.
  5. Rotate or remove any service principal secret older than your policy allows.

Safeguard's compliance and evidence automation can help you show how access is controlled, and a free dependency scan is at gold.safeguard.sh/scan.

Quick check

Does MFA apply to service principals?

Per Microsoft's documentation, no. The requirement covers user identities, not workload identities.

Is a refresh token as sensitive as a password?

Treat it that way. It can be exchanged for new access tokens until it expires or is revoked.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.