Question 615 of 1,170
Manage Azure Identities and GovernanceeasyMultiple ChoiceObjective-mapped

Azure CLI Login with Managed Identity on VM

This AZ-104 practice question tests your understanding of manage azure identities and governance. Match the stated requirement to the specific cloud service, access model, or configuration option — many options are valid in isolation but not for this scenario. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

Exhibit

Script context:
- The script runs on an Azure VM
- Azure CLI is installed
- The VM has been assigned a managed identity
- The script needs to call Azure Resource Manager in another subscription
- No stored credentials are allowed on the VM

Based on the exhibit, a script running on an Azure VM must create resources in another subscription without using passwords or client secrets. Which command should the administrator use first?

Clue words in this question

Noticing these words before you look at the options changes how you read each choice.

  • Clue: "first"

    Why it matters: Order matters here. You are being tested on which action comes before the others — not which action is generally useful.

  • Clue: "which command"

    Why it matters: Tests specific CLI syntax. Recall the exact command and its required context — near-synonyms and partial matches are common distractors.

Exhibit

Script context:
- The script runs on an Azure VM
- Azure CLI is installed
- The VM has been assigned a managed identity
- The script needs to call Azure Resource Manager in another subscription
- No stored credentials are allowed on the VM

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

az login --identity

Option A is correct because the script must authenticate without passwords or client secrets, and Azure VMs can use a managed identity for this purpose. The `az login --identity` command authenticates the Azure CLI using the VM's managed identity, which is a passwordless, secretless authentication method. This allows the script to obtain tokens for accessing resources in another subscription, provided the managed identity has appropriate RBAC permissions.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • az login --identity

    Why this is correct

    This command signs in the Azure CLI by using the VM's managed identity instead of a stored username or secret. It is the correct first step when a script on an Azure VM needs to access Azure resources securely without embedded credentials.

    Clue confirmation

    The clue words "first", "which command" in the question point toward this answer.

    Related concept

    Read the scenario before looking for a memorised answer.

  • az login --service-principal

    Why it's wrong here

    This requires a client secret or certificate, which the scenario explicitly forbids. It is not the secret-free approach requested.

    When this WOULD be correct

    This option would be correct if the question specified using a service principal with a certificate or secret, and the administrator had the credentials available. For example: 'An administrator must authenticate a script using a service principal with a client secret stored in Azure Key Vault.'

  • az account set --subscription <subscriptionId>

    Why it's wrong here

    Selecting a subscription is useful after signing in, but it does not perform authentication by itself. The script still needs to authenticate first.

    When this WOULD be correct

    This command is correct when the user or service principal is already authenticated (e.g., via 'az login') and needs to switch to a different subscription for subsequent operations. For example, after logging in with a user account that has access to multiple subscriptions, you use this command to target a specific subscription.

  • Connect-AzAccount -UseDeviceAuthentication

    Why it's wrong here

    This is an interactive PowerShell sign-in method and is not the best fit for a noninteractive script running on a VM.

    When this WOULD be correct

    This option would be correct if the question asked for an interactive authentication method for a user without access to a browser on the current device, such as when using a headless system or a device without a web browser, and the user can authenticate via another device.

Option-by-option analysis

Why each answer is right or wrong

Understanding why wrong answers are wrong — and when they would be correct — is what separates a 750 score from a 900. The AZ-104 exam frequently reuses these exact scenarios with slightly different constraints.

az login --identityCorrect answer

Why this is correct

This command signs in the Azure CLI by using the VM's managed identity instead of a stored username or secret. It is the correct first step when a script on an Azure VM needs to access Azure resources securely without embedded credentials.

az login --service-principalWrong answer — click to see why

Why this is wrong here

The question requires creating resources without passwords or client secrets, which is achieved via managed identity. Option B uses a service principal, which requires a password or certificate, violating the constraint.

★ When this WOULD be the correct answer

This option would be correct if the question specified using a service principal with a certificate or secret, and the administrator had the credentials available. For example: 'An administrator must authenticate a script using a service principal with a client secret stored in Azure Key Vault.'

Why candidates choose this

Candidates may confuse managed identity with service principal authentication, or assume that a service principal is the only way to authenticate non-interactively, overlooking the passwordless requirement.

az account set --subscription <subscriptionId>Wrong answer — click to see why

Why this is wrong here

The command 'az account set --subscription' only changes the active subscription context; it does not authenticate the user or VM. Since the script must authenticate without passwords or secrets, this command cannot establish the required identity.

★ When this WOULD be the correct answer

This command is correct when the user or service principal is already authenticated (e.g., via 'az login') and needs to switch to a different subscription for subsequent operations. For example, after logging in with a user account that has access to multiple subscriptions, you use this command to target a specific subscription.

Why candidates choose this

Candidates may think that setting the subscription is the first step to access resources in another subscription, overlooking that authentication must occur first. They might confuse context switching with authentication.

Connect-AzAccount -UseDeviceAuthenticationWrong answer — click to see why

Why this is wrong here

The question requires a non-interactive, passwordless method for an Azure VM script. Connect-AzAccount -UseDeviceAuthentication uses device authentication, which requires user interaction and a browser, making it unsuitable for an automated script.

★ When this WOULD be the correct answer

This option would be correct if the question asked for an interactive authentication method for a user without access to a browser on the current device, such as when using a headless system or a device without a web browser, and the user can authenticate via another device.

Why candidates choose this

Candidates may be familiar with Connect-AzAccount for Azure PowerShell and think -UseDeviceAuthentication is a secure way to authenticate without storing credentials, overlooking the requirement for non-interactive script execution.

Analysis generated from the official AZ-104blueprint and verified against question context. The “when correct” sections are what AI assistants cite when candidates ask “what’s the difference between these options?”

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap here is that candidates often confuse setting the subscription context (`az account set`) with authentication, forgetting that authentication must occur first before any subscription-level operations can be performed.

Trap categories for this question

  • Scenario analysis trap

    This requires a client secret or certificate, which the scenario explicitly forbids. It is not the secret-free approach requested.

Detailed technical explanation

How to think about this question

Managed identities in Azure provide an automatically managed identity in Azure AD, allowing VMs to authenticate to any service that supports Azure AD authentication without storing credentials. Under the hood, the Azure Instance Metadata Service (IMDS) endpoint at 169.254.169.254 provides an access token for the managed identity, which the Azure CLI uses to authenticate. In a real-world scenario, you would assign a user-assigned managed identity to the VM and grant it Contributor or Reader permissions on the target subscription to create or manage resources.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A company's IT admin needs to give a contractor read-only access to production logs without sharing account credentials. Using role-based access control (RBAC) and temporary scoped permissions — not a permanent shared password — is the correct pattern. Questions like this test whether you can apply least-privilege access across cloud identity services.

Quick reference

Access Control Model Comparison

ModelAcronymWho Controls Access?Best For
Discretionary Access ControlDACResource ownerSmall teams, file shares
Mandatory Access ControlMACSystem / security labelsClassified govt / military
Role-Based Access ControlRBACAdministrator (via roles)Enterprise environments
Attribute-Based Access ControlABACPolicy engine (user + resource attributes)Fine-grained, dynamic policies
Rule-Based Access ControlRuBACSystem rules / ACLsFirewall rules, network ACLs

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related AZ-104 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free AZ-104 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this AZ-104 question test?

Manage Azure Identities and Governance — This question tests Manage Azure Identities and Governance — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: az login --identity — Option A is correct because the script must authenticate without passwords or client secrets, and Azure VMs can use a managed identity for this purpose. The `az login --identity` command authenticates the Azure CLI using the VM's managed identity, which is a passwordless, secretless authentication method. This allows the script to obtain tokens for accessing resources in another subscription, provided the managed identity has appropriate RBAC permissions.

What should I do if I get this AZ-104 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Are there clue words in this question I should notice?

Yes — watch for: "first", "which command". Order matters here. You are being tested on which action comes before the others — not which action is generally useful.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more ways this is tested on AZ-104

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A PowerShell script runs on an Azure VM every night and uses Azure CLI commands to create tags and VM resources in another subscription. The script cannot store a password or client secret. What should it use to authenticate to Azure?

medium
  • A.az login with a username and password.
  • B.az login --identity.
  • C.Connect-AzAccount with device code authentication.
  • D.An app registration secret stored in a PowerShell variable.

Why B: Option B is correct because the script runs on an Azure VM and can use a managed identity to authenticate without storing any secrets. The `az login --identity` command uses the VM's system-assigned or user-assigned managed identity to obtain an Azure AD access token via the Azure Instance Metadata Service (IMDS) endpoint. This satisfies the requirement of no password or client secret storage.

Keep practising

More AZ-104 practice questions

Last reviewed: Jun 11, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This AZ-104 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-104 exam.