gpt4 book ai didi

azure - 设置adminPassword无效; linux部署在Azure资源管理器中

转载 作者:行者123 更新时间:2023-12-03 02:56:56 26 4
gpt4 key购买 nike

我正在使用 ARM 模板来部署 Linux 计算机。在我的 Microsoft.Compute/virtualMachines 部署中,我的属性包括此内容(以下 the docs )

    "osProfile": {
"computerName": "computer-name-here",
"adminUsername": "[parameters('AdminUserName')]",
"adminPassword": "password following rules here",
"linuxConfiguration": {
"disablePasswordAuthentication": false
}
"secrets": []
},

问题是使用该用户名和密码登录不适用于虚拟机。

当机器旋转时,ssh user@host 失败,表示公钥身份验证失败。当我使用特殊标志强制要求输入密码时,结果相同。

当我检查虚拟机的自动化脚本时,我发现我的属性已通过,但缺少 adminPassword。我假设他们为了安全起见将其从控制台中删除,但 SSH 客户端确实让它看起来像是忽略了我配置的参数并启用了仅 ssh key 访问。

是否可以使用 Azure 进行用户名/密码登录,还是我错过了什么?

编辑更多详细信息:

生成我的 osProfile 的方式是通过一个模板来执行此操作:(请注意,我在用户名前面添加了“密码”,以确保替换正确)

    "authConfig-sshpublickey": {
"adminUsername": "[concat('pubkey-',parameters('AdminUserName'))]",
"adminPassword": "",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "[concat('/home/', parameters('AdminUserName'),'/.ssh/authorized_keys')]",
"keyData": "[parameters('AdminCredential')]"
}
]
}
}
},
"authConfig-password": {
"adminUsername": "[concat('password-',parameters('AdminUserName'))]",
"linuxConfiguration": null,
"adminPassword": "[parameters('AdminCredential')]"
},
"authConfig": "[variables(concat('authConfig-',parameters('AdminAuthType')))]"

然后我在虚拟机中进行如下设置:

    "osProfile": {
"computerName": "[concat(variables('namePrefixes').vm, '-', copyIndex())]",
"adminUsername": "[variables('authConfig').adminUsername]",
"adminPassword": "[variables('authConfig').adminPassword]",
"linuxConfiguration": "[variables('authConfig').linuxConfiguration]"
},

因为在运行时我使用 AdminAuthType=password,所以它会进行替换。

我运行该模板,它正确设置了我的所有基础架构,然后我进入 Azure 控制台,检查生成的 VM 的自动化脚本,然后我看到了以下内容:

            "osProfile": {
"computerName": "[parameters('extra stuff here')]",
"adminUsername": "password-myuser",
"linuxConfiguration": {
"disablePasswordAuthentication": false
},
"secrets": []
},

所以,结论:

  1. 基于密码验证进行替换
  2. 当我明确告诉它不要插入 linuxConfiguration 时,它正在插入。
  3. adminPassword 没有显示在自动化脚本中,但正如之前所说,我不确定这是否是出于安全原因,或者它实际上从未通过。

最佳答案

确切的答案是肯定的,可以在Azure上通过用户名/密码登录。使用您发布的模板,您可以忽略属性“linuxConfiguration”和“secrets”。简单的模板可以是这样的:

"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},

没有属性“linuxConfiguration”,因此不会配置 ssh key 。整个模板示例如下:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"type": "string",
"metadata": {
"description": "User name for the Virtual Machine."
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"dnsLabelPrefix": {
"type": "string",
"metadata": {
"description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
}
},
"ubuntuOSVersion": {
"type": "string",
"defaultValue": "16.04.0-LTS",
"allowedValues": [
"12.04.5-LTS",
"14.04.5-LTS",
"15.10",
"16.04.0-LTS"
],
"metadata": {
"description": "The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'salinuxvm')]",
"imagePublisher": "Canonical",
"imageOffer": "UbuntuServer",
"nicName": "myVMNic",
"addressPrefix": "10.0.0.0/16",
"subnetName": "Subnet",
"subnetPrefix": "10.0.0.0/24",
"storageAccountType": "Standard_LRS",
"publicIPAddressName": "myPublicIP",
"publicIPAddressType": "Dynamic",
"vmName": "MyUbuntuVM",
"vmSize": "Standard_A1",
"virtualNetworkName": "MyVNET",
"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "2017-06-01",
"location": "[parameters('location')]",
"sku": {
"name": "[variables('storageAccountType')]"
},
"kind": "Storage",
"properties": {}
},
{
"apiVersion": "2017-04-01",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
}
}
},
{
"apiVersion": "2017-04-01",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]"
}
}
]
}
},
{
"apiVersion": "2017-04-01",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "2017-03-30",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[variables('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[parameters('ubuntuOSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
},
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName')), '2016-01-01').primaryEndpoints.blob)]"
}
}
}
}
],
"outputs": {
"hostname": {
"type": "string",
"value": "[reference(variables('publicIPAddressName')).dnsSettings.fqdn]"
},
"sshCommand": {
"type": "string",
"value": "[concat('ssh ', parameters('adminUsername'), '@', reference(variables('publicIPAddressName')).dnsSettings.fqdn)]"
}
}
}

此外,NSG 规则将检查是否允许流量。希望这会对您有所帮助。

更新

当您创建带有密码的虚拟机时,创建虚拟机后模板中的密码配置如下所示,出于安全考虑,您看不到密码:

enter image description here

如果您使用公共(public) ssh key 创建 VM,它将如下所示:

enter image description here

您在发布的用于创建虚拟机的模板中设置了两种身份验证方式。请选择一项进行设置。如果您选择密码,请按照我上面发布的模板进行操作。

关于azure - 设置adminPassword无效; linux部署在Azure资源管理器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52257808/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com