【发布时间】:2021-04-17 15:55:16
【问题描述】:
我正在关注windows quickstart for creating a VM in azure powershell
我被困在这里:
# Configure the SSH key
$sshPublicKey = cat ~/.ssh/id_rsa.pub
Add-AzVMSshPublicKey `
-VM $vmconfig `
-KeyData $sshPublicKey `
-Path "/home/azureuser/.ssh/authorized_keys"
首先我认为下面的代码是错误的,因为cat 返回System.String[] 并且逐字运行会导致
Add-AzVMSshPublicKey : Cannot convert 'System.Object[]' to the type 'System.String'
所以...我改用Get-Content "./path/to/file" -raw,它只返回一个字符串,并且命令运行没有错误
现在当我跑步时
New-AzVM `
-ResourceGroupName $resourceGroupName `
-Location $location -VM $vmConfig
我收到以下错误,这意味着我之前设置的 keyData 设置不正确。
New-AzVM : The value of parameter linuxConfiguration.ssh.publicKeys.keyData is invalid.
我找到了问题 - 所以 Azure 密钥保管库给了我一个 PEM 公钥,格式为 -----开始公钥----- MIIBojANBgkqhkiG9w0BAQEFAAO... ... ... ... ...0CS94AFAgMBAAE= -----结束公钥-----
而虚拟机期望它采用 OpenSSH 格式
ssh-rsa ....
我尝试将其转换为 ssh-keygen -i -m PKCS8 -f ./key.pem 但没有任何输出
更新 啊,这是powershell issue
【问题讨论】:
-
您的 SSH 密钥 (~/.ssh/id_rsa.pub) 是否以 ssh-rsa...开头?
-
关于这个问题的任何更新?它解决了你的问题吗?
-
您好,密钥以 -----BEGIN PUBLIC KEY----- 开头
标签: windows azure powershell azure-powershell