6

When I try to login using azure cli by providing username and password. I get error

az login -u myemail@email.com -p plaintextpassword

The user name might be invalid. For cross-check, try 'az login' to authenticate through browser.

When I use browser authentication method with the same username and password I am able to login. Using this process I get the option of "Work or school account" or "personal account". I select "work or school account" and enter my credentials. Is there a way to select this using command line option.

kumar
  • 379
  • 2
  • 6
  • 19

2 Answers2

6

When your account is Microsoft account(such as *@outlook.com, *@hotmail.com), you will get the error log. The root reason is Microsoft account does not support non-interactive login. It is also unsafe for you to login Azure with your account directly.

If you plan to manage your app or service with Azure CLI 2.0, you should run it under an Azure Active Directory (AAD) service principal rather than your own credentials. Please refer to the following steps to create service principal.

1.Login to Azure.

2.Use az ad sp create-for-rbac to create the service principal.

az ad sp create-for-rbac --name {appId} --password "{strong password}" 

Example

az ad sp create-for-rbac --name shuiexample --password "Password012!!" 

You could get result like below:

{
  "appId": "bca24913-026d-4020-b9f1-add600bf9045",
  "displayName": "shuiexample1234",
  "name": "http://shuiexample1234",
  "password": "*******",
  "tenant": "*******"
}

3.Sign in using the service principal using the following:

$appID="bca24913-026d-4020-b9f1-add600bf9045"
$password="******"
$tenant="*******"
az login --service-principal -u $appID --password $password --tenant $tenant

More information about this please refer to this link.

Mike Wise
  • 103
  • 4
Shui shengbao
  • 3,503
  • 1
  • 10
  • 20
  • 2
    I get this error : az: error: unrecognized arguments: --password ***** – Ehsan Zargar Ershadi Jul 05 '19 at 16:20
  • As of Azure CLI 2.0.68, the --password parameter to create a service principal with a user-defined password is no longer supported to prevent the accidental use of weak passwords. – user59050 May 05 '20 at 12:15
1

Is the account you are using a Microsoft account or require multifactor authentication? either of these will require interactive log-in

https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli

Michael Brown
  • 3,204
  • 2
  • 9
  • 10