I wanted to use the Az CLI commands with two separate accounts – my work and personal. I thought that if I opened two separate terminal windows that’d do the trick but turns out it doesn’t. Both terminal windows share the same login info etc.
Then I came across this issue. Turns out there’s an environment variable wherein you can set the location of your Azure config. I use macOS and in my case the Az CLI commands create a folder called “.Azure” in my home directory and use that to store info. So I created a new folder called “.Azure-personal” and in the terminal window where I want to login with my personal account I did the following:
1 |
export AZURE_CONFIG_DIR=~/.Azure-personal |
After that I used the “az login” etc. commands as usual and was able to have two separate instances running in parallel.
To make it easy I added two functions to my bash profile:
1 2 3 4 5 6 7 8 9 |
function az_login_work { export AZURE_CONFIG_DIR=~/.Azure az login --use-device-code } function az_login_personal { export AZURE_CONFIG_DIR=~/.Azure-personal az login --use-device-code } |
Now I can invoke the appropriate function and it will log me in correctly.