How To Login To Azure With a Service Principal

This post will show how to log in to Microsoft Azure using a Service Principal identity and manage resources.

A service principal is an identity created in Azure Active Directory (Azure AD) that is used to authenticate and authorize access to Azure resources. It is similar to a user account, but instead of being associated with a human, it is associated with an application or service.

Create a Service Principal

To create a service principal using Azure CLI, please use the following post, which will guide you and note down the command output. The output will look like this.

{
  "appId": "<app-id>",
  "displayName": "<app-name>",
  "password": "<app-password>",
  "tenant": "<tenant-id>"
}

Login

To log in using a Service Principal, run the following command using the above values.

Note: Use appId for CLIENT_ID, password for CLIENT_SECRET and tenant for TENANT_ID

az login --service-principal -u CLIENT_ID -p CLIENT_SECRET --tenant TENANT_ID

Once logged in with the service principal, you can use Azure CLI, or Azure PowerShell commands to manage Azure resources.

Processing…
Success! You're on the list.

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.