Choose your subscription when logging into Azure using Azure CLI

With the preview release of Azure CLI 2.59.0, there's a new login feature that provides a list of available tenants and subscriptions. Choose to keep the subscription and tenant that is selected by default, or type the line number of the subscription you want to use. Here are the details:

  • The subscription selector is available in a preview version of Azure CLI 64-bit Windows, Linux, or macOS.
  • The subscription selector is only available when using the az login command interactively.
  • The authentication preview must be installed to use the subscription selector.
  • The preview is installed in the directory you specify, and coexists with your current Azure CLI installation.
  • The authentication preview doesn't prompt you to select a subscription when you're logging in with a service principal, managed identity, or Web Account Manager (WAM).

With the current practice, the az account set command is required to change your subscription. With the subscription selector at time of interactive login, you skip having to list and set your default subscription.

Install for Windows

Install Azure CLI authentication preview by following these steps:

  1. Download Microsoft Azure CLI.zip.
  2. Unzip the package to a folder.
  3. Change your working directory to <unzipped folder path\bin\>

Note

You must execute Azure CLI commands from the location where you installed the preview, or update your PATH environment variable to include the location. This article takes the approach of changing the working directory.

Install for Linux and macOS

If you're installing the preview in a macOS environment, Python runtime must be installed.

mkdir azure-cli-edge-build 
cd azure-cli-edge-build 
git clone https://github.com/Azure/azure-cli --branch login --depth 1 
python3 -m venv env 
. env/bin/activate 
pip install azdev 
azdev setup -c 
az login 

Log into Azure

To use the new subscription selector, first change your directory to where you installed the authentication preview, then use ./az.cmd login.

cd <unzipped folder path>
./az.cmd login

If you installed the authentication preview in C:\myPath\Azure CLI preview, your syntax would look like this:

cd "C:\myPath\Azure CLI preview\bin"
C:\myPath\Azure CLI preview\bin> ./az.cmd login

Choose your subscription

  1. Note the subscription and tenant currently selected are indicated with an asterisk (*).
  2. Tap Enter to bypass the subscription selector and accept the default subscription.
  3. Type a line number from the numbered list to change the default subscription.

Here's a screen print of what you can expect from the authentication preview:

Subscription selector

Verify results

To verify your selected default subscription, use ./az.cmd account show. If you installed the authentication preview in C:\myPath\Azure CLI preview, your syntax would look like this:

C:\myPath\Azure CLI preview\bin> ./az.cmd account show

See also