13

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?

Buchi
  • 1,322
  • 4
  • 14
  • 33

3 Answers3

13

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.

  • Tracking the further discussion in https://github.com/Azure/azure-xplat-cli/issues/2198 for interested. – Buchi Oct 15 '15 at 17:55
8

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

Community
  • 1
  • 1
Hrishikesh Kumar
  • 356
  • 2
  • 12
2

For Windows, here are steps

  1. Go to env variables and add AZURE_CONFIG_DIR with the value of new config folder (e.x. C:\Users\YourUser\.azure-personal)
  2. restart your cli, then run this az login --use-device-code
  3. use the code given on step 2 and use it with whatever browser to login to new azure account

Now, one of your accounts config is in default azure folder config (C:\Users\YourUser\.azure) and new one lives in the place you specified on step 1.

if you wanna switch between them, you need to flip that env variable to point to whatever config you want

Ali Abdoli
  • 529
  • 5
  • 9