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

问题描述 投票:0回答:1

我正在使用ARM模板来部署linux机器。在我的Microsoft.Compute/virtualMachines部署中,我有包括这个属性(以下the docs

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

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

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

当我检查VM的自动化脚本时,我看到我的属性已经通过,但缺少adminPassword。我假设他们正在从控制台中删除它以确保安全性,但是SSH客户端肯定会让它看起来像忽略了我配置的参数并只启用了ssh密钥访问。

是否可以使用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')))]"

然后我在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": []
            },

所以,结论:

  1. 它取代了密码验证
  2. 当我明确告诉它时,它正在插入linuxConfiguration。
  3. adminPassword没有显示在自动化脚本中,但如前所述,我不确定这是出于安全原因,还是从未真正实现过。
azure virtual-machine azure-resource-manager
1个回答
1
投票

确切的答案是肯定的,可以通过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后模板中的密码配置如下所示,由于安全性,您无法看到密码:

enter image description here

如果使用公共ssh密钥创建VM,它将是这样的:

enter image description here

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

© www.soinside.com 2019 - 2024. All rights reserved.