我们的团队正在使用Azure PowerShell来创build和初始化Linux VM。 我对Azure一点都不熟悉,但是试图帮助其他人设置它。 有没有办法提供一个自定义的authorized_keys文件,并有Azure PowerShell放在〜/ .ssh? 我们希望这在创build时自动发生。
正如@modo在评论中提到的,你可以使用“ 自定义脚本扩展 ”来实现这个目标。
如果您正在使用ARM VM:
$RGName = '<resource-group-name>' $VmName = '<vm-name>' $Location = '<location>' $ExtensionName = 'CustomScriptForLinux' $Publisher = 'Microsoft.OSTCExtensions' $Version = '<version>' $PublicConf = '{ "fileUris": ["<url>"], "commandToExecute": "<command>" }' $PrivateConf = '{ "storageAccountName": "<storage-account-name>", "storageAccountKey": "<storage-account-key>" }' Set-AzureRmVMExtension -ResourceGroupName $RGName -VMName $VmName -Location $Location ` -Name $ExtensionName -Publisher $Publisher ` -ExtensionType $ExtensionName -TypeHandlerVersion $Version ` -Settingstring $PublicConf -ProtectedSettingString $PrivateConf
如果您正在使用ASM VM:
$VmName = '<vm-name>' $vm = Get-AzureVM -ServiceName $VmName -Name $VmName $ExtensionName = 'CustomScriptForLinux' $Publisher = 'Microsoft.OSTCExtensions' $Version = '<version>' $PublicConf = '{ "fileUris": ["<url>"], "commandToExecute": "<command>" }' $PrivateConf = '{ "storageAccountName": "<storage-account-name>", "storageAccountKey": "<storage-account-key>" }' Set-AzureVMExtension -ExtensionName $ExtensionName -VM $vm ` -Publisher $Publisher -Version $Version ` -PrivateConfiguration $PrivateConf -PublicConfiguration $PublicConf | Update-AzureVM