Sign in with the Azure CLI

This page explains how to use the Azure CLI to sign in to Azure Databricks with either a user account or a Microsoft Entra ID service principal.

Sign in as a user

Follow these steps to use the Azure CLI to sign in to Azure Databricks with a user account.

  1. Get your Azure subscription ID:

    • Azure portal: In your Azure Databricks workspace, click your username > Azure Portal > Overview. Copy the Subscription ID.
    • Azure CLI: Run the following command, replacing adb-0000000000000000.0.databricks.azure.cn with your workspace URL (without https://). The subscription ID appears after /subscriptions/ in the output.
    az databricks workspace list --query "[?workspaceUrl==\`adb-0000000000000000.0.databricks.azure.cn\`].{id:id}" -o tsv
    
    # /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Databricks/workspaces/my-ws
    

    If you see The subscription of '<subscription-id>' doesn't exist in cloud 'AzureCloud', get your tenant ID by running curl -v <per-workspace-URL>/aad/auth (look for the ID in the location response) or see Get subscription and tenant IDs. Then sign in with: az login -t <tenant-id>

  2. Sign in to Azure and follow the on-screen instructions:

    az cloud set -n AzureChinaCloud
    az login
    # az cloud set -n AzureCloud   //means return to Public Azure.
    
  3. Set the correct subscription:

    az account set -s <subscription-id>
    

Sign in as a Microsoft Entra ID service principal

To sign in with a Microsoft Entra ID service principal, gather the following from your Microsoft Entra ID application:

  • Tenant ID: Directory (tenant) ID

  • Client ID: Application (client) ID

  • Client secret: The secret value

  • Subscription ID: Get this from Azure Portal (workspace Overview page) or through the CLI:

    az databricks workspace list --query "[?workspaceUrl==\`adb-0000000000000000.0.databricks.azure.cn\`].{id:id}" -o tsv
    
    # /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Databricks/workspaces/my-ws
    

Use the values to sign in:

az cloud set -n AzureChinaCloud
# az cloud set -n AzureCloud   //means return to Public Azure.
az login \
--service-principal \
-t <Tenant-ID> \
-u <Client-ID> \
-p <Client-secret>

Then set your subscription:

az account set -s <subscription-id>