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

设置adminPassword无效;在Azure资源管理器中部署linux,azure,virtual-machine,azure-resource-manager,Azure,Virtual Machine,Azure Resource Manager,我正在使用ARM模板部署linux机器。在我的Microsoft.Compute/virtualMachines部署中,我有包括以下内容的属性 问题是,使用该用户名和密码登录的虚拟机无法使用 当机器旋转时,然后sshuser@host失败,表示公钥身份验证失败。当我使用特殊标志强制要求输入密码时,结果也是一样的 当我检查VM的自动化脚本时,我看到我的属性通过了,但是adminPassword丢失了。我假设为了安全起见,他们正在从控制台中删除它,但是SSH客户端确实让它看起来好像忽略了我配置的参数

我正在使用ARM模板部署linux机器。在我的
Microsoft.Compute/virtualMachines
部署中,我有包括以下内容的属性

问题是,使用该用户名和密码登录的虚拟机无法使用

当机器旋转时,然后
sshuser@host
失败,表示公钥身份验证失败。当我使用特殊标志强制要求输入密码时,结果也是一样的

当我检查VM的自动化脚本时,我看到我的属性通过了,但是adminPassword丢失了。我假设为了安全起见,他们正在从控制台中删除它,但是SSH客户端确实让它看起来好像忽略了我配置的参数并启用了SSH密钥访问

是否可以使用Azure登录用户名/密码,或者我是否遗漏了什么

编辑更多详细信息:

我的osProfile是通过一个模板生成的:(注意,我在用户名前加了“密码”,以确保替换是正确的)

然后我在VM中设置它,如下所示:

    "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": []
            },
因此,结论如下:

  • 它是在密码验证的基础上进行替换的
  • 当我明确告诉它不要这样做时,它正在插入linuxConfiguration
  • adminPassword没有显示在自动化脚本中,但正如前面所说的,我不确定这是出于安全原因,还是它从未真正通过

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

    "osProfile": {
                        "computerName": "[variables('vmName')]",
                        "adminUsername": "[parameters('adminUsername')]",
                        "adminPassword": "[parameters('adminPassword')]"
                    },
    
    没有属性“linuxConfiguration”,因此不会配置ssh密钥。整个模板示例如下:

    {
        "$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规则是否允许通信。希望这对你有帮助

    更新

    使用密码创建VM时,创建VM后模板中的密码配置如下所示,由于安全原因,您无法看到密码:

    如果使用公共ssh密钥创建VM,它将如下所示:

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


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

    您是否尝试过
    ssh用户:password@host
    ?仅使用此配置—这不起作用。看起来VM仍然需要公钥身份验证。例如,我试图使用ssh-o PreferredAuthentications=password-o PubkeyAuthentication=no登录myuser@host结果是
    权限被拒绝(公钥)
    NSG规则已就位。当我将VM配置为使用ssh密钥而不是密码时,一切正常。在我这边,当我通过密码连接VM时,一切正常。你能发布你的模板来提供更多的细节吗?如果你能再看一眼,我将非常感激。在文章的编辑点下方,我发布了更多关于我的模板如何工作、生成了什么以及我在Azure中看到了什么的详细信息。在我看来,它似乎忽略了我的密码并重新添加了SSH密钥验证,我似乎无法避免这一点。在这些配置设置下(Azure实际应用的是什么,而不是我指定的)——登录失败是有道理的,因为本质上它似乎是为SSH密钥验证设置的,但没有有效的密钥,也没有密码,所以密码登录似乎无法工作。但很明显我遗漏了什么。
    {
        "$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)]"
            }
        }
    }