Az CLI and multiple accounts

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:

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:

Now I can invoke the appropriate function and it will log me in correctly.