If you are encountering the error message "Found multiple accounts with the same username" while trying to log in to Azure CLI using the AZ LOGIN command, don't worry! This article will guide you through the steps to resolve this issue.
When you see this error, it means that there are multiple Azure Active Directory (Azure AD) accounts associated with the same username. Azure CLI is unable to determine which account to use for authentication, leading to the error message. To fix this, you need to specify the correct account you want to use.
Follow the steps below to resolve the "Found multiple accounts with the same username" error:
Step 1: List Azure AD Accounts
Open your preferred command-line interface, such as Command Prompt or PowerShell, and enter the following command:
az account list
This command will display a list of all the Azure AD accounts associated with your username. Take note of the account IDs and their corresponding names.
Step 2: Set the Default Azure AD Account
Once you have identified the correct Azure AD account you want to use, set it as the default account by running the following command:
az account set --subscription <subscription_id>
Replace <subscription_id> with the ID of the desired Azure AD account.
For example, if the account ID is "12345678-1234-1234-1234-1234567890ab", the command will be:
az account set --subscription 12345678-1234-1234-1234-1234567890ab
This command sets the specified Azure AD account as the default for all Azure CLI commands.
Step 3: Log in to Azure CLI
Now that you have set the default Azure AD account, you can log in to Azure CLI using the AZ LOGIN command. Run the following command:
az login
This command will prompt you to authenticate with your Azure AD credentials. Enter your username and password when prompted.
If the authentication is successful, you will be logged in to Azure CLI with the specified Azure AD account.
Congratulations! You have successfully resolved the "Found multiple accounts with the same username" error and logged in to Azure CLI.
If you encounter any further issues or errors, it is recommended to check the Azure CLI documentation or seek assistance from the Azure support community.
Summary
In this article, we discussed the steps to resolve the "Found multiple accounts with the same username" error while logging in to Azure CLI. By specifying the correct Azure AD account and setting it as the default, you can successfully log in to Azure CLI and continue managing your Azure resources.
References
| Reference | Link |
|---|---|
| Azure CLI Documentation | https://docs.microsoft.com/en-us/cli/azure/ |
| Azure Support Community | https://azure.microsoft.com/en-us/support/community/ |