How to Sign In to Two Accounts at Once in the Azure CLI
The Azure CLI keeps your sign-in in a configuration folder, ~/.azure by default, and the environment variable AZURE_CONFIG_DIR points a command at another folder. Sign a second account in to a folder of its own, and both accounts stay signed in at once: each az command uses the account of the folder you give it.
Why a folder of its own? A sign-in changes the folder it's saved in. Microsoft's guide to managing subscriptions says to Use az login to change the active tenant and update the subscription list to which you belong. Sign the second account in to the default folder, and those changes land in the folder your own commands use.
AZURE_CONFIG_DIR keeps the two apart. It tells the Azure CLI which configuration folder to use, so the second account's sign-in goes to its own folder and yours stays where it is.
Syntax
- bash / zsh
- PowerShell
AZURE_CONFIG_DIR=<folder> az <command>
$env:AZURE_CONFIG_DIR = <folder>
az <command>
Remove-Item Env:AZURE_CONFIG_DIR
| Part | What it is |
|---|---|
AZURE_CONFIG_DIR | The environment variable that sets the Azure CLI's configuration folder. When it isn't set, the folder is $HOME/.azure on Linux and macOS, and %USERPROFILE%\.azure on Windows |
<folder> | The second account's own folder, which no other account uses: for example ~/.azure-test-user in bash and zsh, or Join-Path $HOME ".azure-test-user" in PowerShell |
<command> | Any Azure CLI command. It runs with the sign-in saved in <folder> |
AZURE_CONFIG_DIR=<folder> in front of a command | bash and zsh: sets the variable for that one command. The bash manual says These assignment statements affect only the environment seen by that command. The next command without it uses the default folder again |
$env:AZURE_CONFIG_DIR = <folder> | PowerShell: sets the variable for the rest of the session, so every az command after it uses <folder> |
Remove-Item Env:AZURE_CONFIG_DIR | PowerShell: removes the variable, so the az commands after it use the default folder again |
In PowerShell, the variable stays until you remove it or end the session: When you change environment variables in PowerShell, the change affects only the current session. The az command still sees it, because environment variables are inherited by child processes.
The Example
My own account, user@example.com, is signed in to the Azure CLI in the default folder, ~/.azure. A second account, test.manager@contoso.onmicrosoft.com, is a test user called Test Manager in the same Microsoft Entra tenant, and it has no Azure subscription. I sign it in to a folder of its own, ~/.azure-test-user, use both accounts side by side, and then sign the second one out and delete its folder. My real address and name are replaced with user@example.com and Azure User in the outputs.
I ran every step on macOS with Azure CLI 2.93.0, in zsh and in PowerShell 7.6.
Step 1: Check Which Account the Azure CLI Uses Now
Before the second sign-in, check which account the default folder holds:
az account show --query user.name --output tsv
user@example.com
The command is the same in every shell, and I got this output in both zsh and PowerShell.
az account showshows the subscription the Azure CLI uses. Its reference: Get the details of a subscription. Without a subscription name, it shows the details of the default subscription, and those details include the account that signed in.--query user.namekeeps only that account's name. The Azure CLI uses the--queryparameter to execute a JMESPath query on the results of commands, anduser.namepicksnameinsideuser.--output tsvprints the value as plain text, without the quotes JSON would put around it.
Step 2: Sign the Second Account In to Its Own Folder
- bash / zsh
- PowerShell
AZURE_CONFIG_DIR=~/.azure-test-user az login --tenant contoso.onmicrosoft.com --allow-no-subscriptions
$env:AZURE_CONFIG_DIR = Join-Path $HOME ".azure-test-user"
az login --tenant contoso.onmicrosoft.com --allow-no-subscriptions
Remove-Item Env:AZURE_CONFIG_DIR
AZURE_CONFIG_DIR=~/.azure-test-user, or$env:AZURE_CONFIG_DIRin PowerShell, sends this sign-in to the second account's folder.Join-Pathcombines a path and child-path into a single path: your home folder and.azure-test-user.az loginsigns in. On macOS and Linux, it initiates authorization code flow and opens the default browser to load an Azure sign-in page.--tenant contoso.onmicrosoft.comsigns in to that Microsoft Entra tenant. The value of this argument can either be a.onmicrosoft.comdomain or the Azure object ID for the tenant. Use your own tenant's domain, or its ID: How to Find Your Microsoft Entra Tenant ID shows where to copy it.--allow-no-subscriptionslets an account without an Azure subscription sign in. The reference describes it as Support accessing tenants without subscriptions. My test user has no subscription, so it needs this option.Remove-Item Env:AZURE_CONFIG_DIR, the third PowerShell line, removes the variable again, so the commands after it use the default folder.
I used the browser sign-in, not a device code: my tenant blocks sign-in with a device code, as Fixed: "You don't have access to this" (Error Code 53003) When You Sign In to the Azure CLI with a Device Code shows.
The sign-in page opened in a browser window that already had the test user signed in, so it asked me to pick an account:

Pick the second account. If the page shows only your own account, choose Use another account and sign in as the second one. After I picked Test Manager, the browser said the sign-in was done:

Back in the terminal, the Azure CLI listed what the account can use and asked which one to keep. N/A(tenant level account) means a sign-in to the tenant without a subscription, the kind --allow-no-subscriptions allows. It was the only choice and already the default, marked with *, so I pressed Enter. The output was the same in zsh and PowerShell:
A web browser has been opened at https://login.microsoftonline.com/11111111-1111-1111-1111-111111111111/oauth2/v2.0/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.
Retrieving subscriptions for the selection...
[Tenant and subscription selection]
No Subscription name Subscription ID Tenant
----- ------------------------- ------------------------------------ ------------------------------------
[1] * N/A(tenant level account) 11111111-1111-1111-1111-111111111111 11111111-1111-1111-1111-111111111111
The default is marked with an *; the default tenant is '11111111-1111-1111-1111-111111111111' and subscription is 'N/A(tenant level account)' (11111111-1111-1111-1111-111111111111).
Select a subscription and tenant (Type a number or Enter for no changes):
Tenant: 11111111-1111-1111-1111-111111111111
Subscription: N/A(tenant level account) (11111111-1111-1111-1111-111111111111)
[Announcements]
With the new Azure CLI login experience, you can select the subscription you want to use more easily. Learn more about it and its configuration at https://go.microsoft.com/fwlink/?linkid=2271236
If you encounter any problem, please open an issue at https://aka.ms/azclibug
[Warning] The login output has been updated. Please be aware that it no longer displays the full list of available subscriptions by default.

The second account is now signed in, in ~/.azure-test-user only.
Step 3: Use Both Accounts
Each az command now uses the account of the folder it gets. Ask both folders who they are: the account name from Step 1, and the name Microsoft Entra ID has for the user.
- bash / zsh
- PowerShell
AZURE_CONFIG_DIR=~/.azure-test-user az account show --query user.name --output tsv
AZURE_CONFIG_DIR=~/.azure-test-user az ad signed-in-user show --query displayName --output tsv
az account show --query user.name --output tsv
az ad signed-in-user show --query displayName --output tsv
$env:AZURE_CONFIG_DIR = Join-Path $HOME ".azure-test-user"
az account show --query user.name --output tsv
az ad signed-in-user show --query displayName --output tsv
Remove-Item Env:AZURE_CONFIG_DIR
az account show --query user.name --output tsv
az ad signed-in-user show --query displayName --output tsv
test.manager@contoso.onmicrosoft.com
Test Manager
user@example.com
Azure User
- The first two commands run with the second account's folder. The last two run without the variable, so they use the default folder.
az ad signed-in-user showasks Microsoft Graph about the account: Get the details for the currently logged-in user.--query displayNamekeeps only the user's display name. Because it calls Microsoft Graph, it also shows that the second sign-in works, not only that its name is saved.

Two accounts, signed in at once: the second folder answers as Test Manager, and the default folder still answers as me.
Step 4: Sign the Second Account Out and Delete Its Folder
When you no longer need the second account, sign it out and delete its folder:
- bash / zsh
- PowerShell
AZURE_CONFIG_DIR=~/.azure-test-user az logout
rm -rf ~/.azure-test-user
ls ~/.azure-test-user
az account show --query user.name --output tsv
ls: /Users/you/.azure-test-user: No such file or directory
user@example.com
$env:AZURE_CONFIG_DIR = Join-Path $HOME ".azure-test-user"
az logout
Remove-Item Env:AZURE_CONFIG_DIR
Remove-Item -Recurse -Force (Join-Path $HOME ".azure-test-user")
Test-Path (Join-Path $HOME ".azure-test-user")
az account show --query user.name --output tsv
False
user@example.com
az logoutwith the second account's folder signs that account out: Log out to remove access to Azure subscriptions. It printed nothing.rm -rf, orRemove-Item -Recurse -Forcein PowerShell, deletes the folder with everything in it.rm -rremoves the whole folder tree and-fdoesn't ask first; in PowerShell,-Recursedeletes the items in the specified locations and in all child items of the locations.lsandTest-Pathcheck that the folder is gone:lsreports No such file or directory, andTest-PathprintsFalse.az account showwithout the variable shows that my own account is still signed in.

When I listed the folder a little after the PowerShell cleanup, ~/.azure-test-user was back, holding only logs/telemetry.log. The last az command that used the folder, az logout, starts a separate telemetry upload process as it ends, and when the folder is deleted right after it, that process can create the folder again for its log. Fixed: A Deleted Azure CLI Configuration Folder Comes Back with logs/telemetry.log shows why, and how to delete it for good.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Running az login for the second account without AZURE_CONFIG_DIR | The sign-in goes to the default folder, and az login changes the active tenant and subscription list your own commands use | Give the second account's commands their own folder |
export AZURE_CONFIG_DIR=~/.azure-test-user in bash or zsh | Every command after it in that shell uses the second account's folder | Put AZURE_CONFIG_DIR=<folder> in front of each command instead |
Leaving $env:AZURE_CONFIG_DIR set in PowerShell | Every az command after it in that session uses the second account | Run Remove-Item Env:AZURE_CONFIG_DIR when you're done |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| "You don't have access to this", Error Code 53003, after entering a device code | Your tenant blocks the device code flow with Conditional Access | Sign in without --use-device-code (Fixed) |
The deleted folder is back, with only logs/telemetry.log in it | The telemetry upload process of the last az command recreated it | Delete it again (Fixed) |
az account show prints the second account where you expected yours | AZURE_CONFIG_DIR is still set in your PowerShell session | Remove-Item Env:AZURE_CONFIG_DIR |
FAQ
Where is the second account's sign-in saved?
In the folder you set. Microsoft's tips page for the Azure CLI says that with AZURE_CONFIG_DIR set, Azure CLI commands in that script save the configuration and token cache to the configured location instead of the default ~/.azure folder. Your own sign-in stays in ~/.azure, as Step 3 shows.
Can both accounts run commands at the same time?
Separate folders are what Microsoft recommends for that: If you run Azure CLI commands concurrently on the same machine, write conflicts can happen if multiple Azure CLI commands write to the same Microsoft Authentication Library (MSAL) token cache. With its own folder, each account's commands write to their own token cache.
Does this work on Windows?
I ran these steps on macOS only. On Windows, az login uses Web Account Manager (WAM) by default instead of a browser page, so Step 2 looks different there: WAM is a Windows 10+ component that acts as an authentication broker. The variable is the same; the tips page also shows it for Cmd, as set AZURE_CONFIG_DIR=D:\my\config\dir. I haven't tried two accounts with WAM.
Conclusion
To keep two accounts signed in to the Azure CLI at once, give the second one its own configuration folder: AZURE_CONFIG_DIR=<folder> in front of its commands in bash and zsh, or $env:AZURE_CONFIG_DIR set before and removed after them in PowerShell. Commands without the variable keep using your own sign-in in ~/.azure. When you're done, sign the second account out with az logout in its folder, delete the folder, and check again a little later that it stayed deleted.
Additional Resources
- Azure CLI configuration — the configuration folder and where it is by default.
- Tips for using the Azure CLI successfully — a separate
AZURE_CONFIG_DIRfor each script. - Sign into Azure interactively using the Azure CLI — the browser sign-in, WAM on Windows and
--tenant. - az login —
--tenantand--allow-no-subscriptions. - How to manage Azure subscriptions with the Azure CLI — what
az loginchanges. - How to query Azure CLI command output using a JMESPath query — the
--queryparameter. - az ad signed-in-user — the account that's signed in, from Microsoft Graph.
- about_Environment_Variables — setting and removing environment variables in PowerShell.
