如何获取使用PowerShell创建的新Azure Linux VM的ssh主机密钥? [英] How can I get the ssh host key for a new Azure Linux VM created using PowerShell?

查看:107
本文介绍了如何获取使用PowerShell创建的新Azure Linux VM的ssh主机密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用PowerShell创建Azure Linux VM,如何获得其新的ssh主机密钥,以便可以将其安装在本地ssh/putty中?最好的解决方案也是PowerShell代码.

If I create an Azure Linux VM using PowerShell, how can I get its new ssh host key, so that I can install it in my local ssh/putty? Preferably the solution is also PowerShell code.

推荐答案

旧问题,但是对于新来者来说,如今可以通过在Azure CLI中使用运行命令来获得另一种选择. PowerShell可能也有一个等效物,但是我还没有对此进行研究.

Old question, but for newcomers there is nowadays an alternative available by using run-command in Azure CLI. There is probably an equivalent for PowerShell too, but I have not investigated that.

az vm run-command invoke --name <your-vm-name> --command-id RunShellScript --scripts "cat /etc/ssh/ssh_host_ecdsa_key.pub"

将输出一个json文档,您可以从中提取公钥.请注意,尽管此过程非常慢(每个主机约30秒),但是您只需要运行一次即可.请参阅此要点,以获取有关如何使用Ansible更新known_hosts文件的示例.

will output a json document from which you can extract the public key. Beware though that this process is incredibly slow (~30 seconds per host), but you only need to run it once. See this gist for an example of how to update the known_hosts file with Ansible.

这篇关于如何获取使用PowerShell创建的新Azure Linux VM的ssh主机密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆