使用 Azure CLI 查看托管标识的服务主体View the service principal of a managed identity using Azure CLI

Azure 资源的托管标识在 Azure Active Directory 中为 Azure 服务提供了一个自动托管标识。Managed identities for Azure resources provides Azure services with an automatically managed identity in Azure Active Directory. 此标识可用于通过支持 Azure AD 身份验证的任何服务的身份验证,这样就无需在代码中插入凭据了。You can use this identity to authenticate to any service that supports Azure AD authentication without having credentials in your code.

本文将介绍如何使用 Azure CLI 查看托管标识的服务主体。In this article, you learn how to view the service principal of a managed identity using Azure CLI.

如果还没有 Azure 帐户,请先注册试用帐户,然后再继续。If you don't already have an Azure account, sign up for a Trial before continuing.

先决条件Prerequisites

  • 如果需要,请安装 Azure CLI 来运行 CLI 参考命令。If you prefer, install the Azure CLI to run CLI reference commands.

    • 如果使用的是本地安装,请使用 az login 命令登录到 Azure CLI。If you're using a local installation, sign in to the Azure CLI by using the az login command. 若要完成身份验证过程,请遵循终端中显示的步骤。To finish the authentication process, follow the steps displayed in your terminal. 有关其他登录选项,请参阅登录 Azure CLIFor additional sign-in options, see Sign in with the Azure CLI.

    • 出现提示时,请在首次使用时安装 Azure CLI 扩展。When you're prompted, install Azure CLI extensions on first use. 有关扩展详细信息,请参阅使用 Azure CLI 的扩展For more information about extensions, see Use extensions with the Azure CLI.

    • 运行 az version 以查找安装的版本和依赖库。Run az version to find the version and dependent libraries that are installed. 若要升级到最新版本,请运行 az upgradeTo upgrade to the latest version, run az upgrade.

查看服务主体View the service principal

以下命令演示如何查看启用了托管标识的 VM 或应用程序的服务主体。This following command demonstrates how to view the service principal of a VM or application with managed identity enabled. <Azure resource name> 替换为自己的值。Replace <Azure resource name> with your own values.

az ad sp list --display-name <Azure resource name>

后续步骤Next steps

有关使用 Azure CLI 管理 Azure AD 服务主体的详细信息,请参阅 az ad spFor more information on managing Azure AD service principals using Azure CLI, see az ad sp.