Azure Add-AzureProvisioningConfig ssh密钥或密钥对上载

时间:2015-11-03 18:55:32

标签: linux powershell azure ssh

使用Azure Powershell命令行开关,我想要配置一个没有SSH密码且只有SSH密钥的新Linux VM(在配置CoreOS时是必需的)。使用Azure CLI以及命令行中指定的公钥文件时,一切正常。显然,这不适用于Powershell命令行开关Add-AzureProvisioningConfig。它需要两个可能的SSH密钥参数,但它们都是密钥对的列表。作为documented here,参数-SSHKeyPairs指定已在订阅中部署的SSH密钥对的列表。我不知道如何在订阅中部署密钥对,也无法在任何地方找到它。同样,-SSHPublicKeys指定已在订阅中部署的SSH公钥列表。

1 个答案:

答案 0 :(得分:1)

您可以使用Openssl.exe实用程序生成证书。

以下是此命令的示例:

openssl.exe req -x509 -nodes -days 365 -newkey rsa:2048 -keyout myPrivateKey.key -out myCert.pem

如何使用SSH配置Linux虚拟机的完整示例:

$location = "West US"
$serviceName = "contosolinux1"
$vmName = "linuxvm1"
$size = "Small"
$adminUser = "[admin user name]"
$password = "[admin password]"
$imageFamily = "Ubuntu Server 14.10 DAILY"
$imageName = Get-AzureVMImage |
where { $_.ImageFamily -eq $imageFamily } |
sort PublishedDate -Descending |
select -ExpandProperty ImageName -First 1
$certPath = "$PSScriptRoot\MyCert.pem"
New-AzureService -ServiceName $serviceName `
-Location $location
$cert = Get-PfxCertificate -FilePath $certPath
Add-AzureCertificate -CertToDeploy $certPath `
-ServiceName $serviceName
$sshKey = New-AzureSSHKey -PublicKey -Fingerprint $cert.Thumbprint `
-Path "/home/$linuxUser/.ssh/authorized_keys"
New-AzureVMConfig -Name $vmName `
-InstanceSize $size `
-ImageName $imageName |
Add-AzureProvisioningConfig -Linux `
-AdminUsername $adminUser `
-Password $password `
-SSHPublicKeys $sshKey |
New-AzureVM -ServiceName $serviceName

来源:https://www.microsoftpressstore.com/store/exam-ref-70-533-implementing-microsoft-azure-infrastructure-9780735697065