Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access multiple azure accounts with azure-cli from the same machine at same time?

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?

like image 617
Buchi Avatar asked Oct 14 '15 23:10

Buchi


People also ask

What are the two primary methods for accessing the Azure CLI?

The Azure CLI for Windows can also be used from a browser through the Azure Cloud Shell or run from inside a Docker container. For Windows, the Azure CLI is installed via a MSI, which gives you access to the CLI through the Windows Command Prompt (CMD) or PowerShell.

Can you have multiple Azure accounts?

The Azure portal supports signing in with multiple accounts and switching between them directly in the portal if the accounts your using support it.

Which is better Azure CLI or PowerShell?

You can use both in Cloud Shell in PowerShell, and you can use both remotely at your workstation to manage the Azure cloud. If it's resources in Azure that you want to manage, then use Azure CLI; and if you need to manage Windows Servers, then use Azure PowerShell.

What is the difference between Azure CLI and azure PowerShell?

Azure CLI has an installer that makes its commands executable in all four shell environments. Azure PowerShell is set of cmdlets packaged as a PowerShell module named Az ; not an executable. Windows PowerShell or PowerShell must be used to install the Az module.


1 Answers

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.

like image 104
Amar Zavery - MSFT Avatar answered Sep 30 '22 03:09

Amar Zavery - MSFT