Connect-AzAccount - 如何避免 Azure 设备身份验证? [英] Connect-AzAccount - how to avoid azure device authentication?

查看:24
本文介绍了Connect-AzAccount - 如何避免 Azure 设备身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 PowerShell 6.1.3 版本并且我想使用以下 Azure PowerShell 命令连接到 Azure 帐户:

I have installed the PowerShell 6.1.3 version and I want to get a connection to the Azure account using the following Azure PowerShell command:

Connect-AzAccount -Tenant <tenantId> -Subscription <subId>

输入此命令后,我收到带有 url 和一些代码的警告.然后我必须转到 URL 并在那里输入代码.之后,我连接到 Azure 帐户.

After entering this command I get the warning with the url and some code. Then I have to go to the URL and enter the code there. After that, I get a connection to the Azure account.

有什么办法可以避免这种确认?

我也尝试过使用以下命令:

I've also tried to do it using the following command:

az login -u <username> -p <password>

此命令仅返回一些帐户信息(subscriptionId、tenantId 等),但不会安装与此帐户的连接.

This command only returns some account information(subscriptionId, tenantId etc) but it doesn't install a connection to this account.

推荐答案

1.要使用用户帐户登录,请尝试以下命令,确保您的帐户未启用 MFA(Multi-Factor Authentication).

1.To login with the user account, try the command as below, make sure your account doesn't enable the MFA(Multi-Factor Authentication).

$User = "xxx@xxxx.onmicrosoft.com"
$PWord = ConvertTo-SecureString -String "<Password>" -AsPlainText -Force
$tenant = "<tenant id>"
$subscription = "<subscription id>"
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User,$PWord
Connect-AzAccount -Credential $Credential -Tenant $tenant -Subscription $subscription

2.您也可以使用服务主体登录,使用如下命令.

2.You can also use a service principal to login, use the command as below.

$azureAplicationId ="Azure AD Application Id"
$azureTenantId= "Your Tenant Id"
$azurePassword = ConvertTo-SecureString "strong password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal 

看到我在这里回答的类似问题,它使用旧的 AzureRM 模块,对于 Az,只需更改最后一行.

See a similar issue I answered here, it use the old AzureRM module, for Az, just change the last line.

如果您不熟悉服务主体,另请参阅:如何:使用门户创建可以访问资源的 Azure AD 应用程序和服务主体应用程序 ID 和身份验证密钥是<您需要的代码>Azure AD 应用程序 ID 和强密码.

If you are not familiar with service principal, Also see : How to: Use the portal to create an Azure AD application and service principal that can access resources, the application id and authentication key are the Azure AD Application Id and strong password you need.

这篇关于Connect-AzAccount - 如何避免 Azure 设备身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆