gpt4 book ai didi

amazon-web-services - AWS EC2 : Safe way to get host public key

转载 作者:行者123 更新时间:2023-12-02 14:09:39 25 4
gpt4 key购买 nike

当我第一次使用 ssh 连接到 AWS EC2 实例时,出现如下错误,因为主机 key 未存储在 ssh known_hosts 文件中。

The authenticity of host 'x.x.x.x' can't be established. ECDSA key fingerprint is xx:yy:.... Are you sure you want to continue connecting (yes/no)?



现在,我正在自动化 ssh。我经常只是在 ssh 命令中添加 StrictHostKeyChecking 选项以避免此消息。
但是,我觉得这不是很安全的方式,可能会导致中间人攻击。
是否有任何(或好的)方法可以在 AWS EC2 上安全地获取主机 key ?

最佳答案

我认为唯一的方法是解析控制台输出。

#get the console output of the instance
aws ec2 get-console-output --instance-id <instance id> |\
#use jq to get the Output field
jq .Output -r |\
#use sed to find the interesting bits
sed -n -e '1,/-----BEGIN SSH HOST KEY KEYS-----/d; /-----END SSH HOST KEY KEYS-----/q; p'

注意事项,根据您的应用程序可能无关紧要:
  • aws输出是 JSON,所以我们需要解析它
  • output requires some sed massage
  • 取决于 AMI,输出可能不一样?
  • 关于amazon-web-services - AWS EC2 : Safe way to get host public key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23331014/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com