5
votes

We actually have multiple azure accounts (for some valid reason) and I want to be able to run azure-cli commands for different accounts at the same time from the same machine.

The problem with that is, once I login to one azure account with azure login, token will be stored in ~/.azure directory so I am not sure if I can login into another account exactly at the same time on that machine.

Is there any way to tell azure-cli not to store token in local profile so that I can use azure-cli to connect to multiple accounts at the same time from same machine?

2

2 Answers

8
votes

If you are using a windows or mac machine then the tokens are stored in Windows token manager or OSx key chain respectively. Only on Linux systems the tokens are stored in ~/.azure/azureProfile.json

However, you should still be able to login with multiple accounts on Win/Mac or Linux machines.

azure account set "subscription-name" will set the subscription as your default subscription and all the commands that you execute will run against that subscription.

Every command has a -s or --subscription switch where you can explicitly specify the subscription id. Even if the subscription belongs to a different account, it should still work if you have authenticated with that account.

For Linux system, I would suggest to create multiple user accounts and then run the CLI from those accounts. I think there could be a race condition when two commands from different accounts try to access ~/.azure/azureProfile.json.

2
votes

The latest update is that the environment variable AZURE_CONFIG_DIR has been introduced and that can be set differently for each environment before az login is called.

export AZURE_CONFIG_DIR=/tmp1

az login

and on other window

export AZURE_CONFIG_DIR=/tmp2

az login

Reference: configure the AZURE_CONFIG_DIR for fixing concurrency issue