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

标签 amazon-web-services ssh amazon-ec2

当我第一次使用 ssh 连接到 AWS EC2 实例时,出现如下错误,因为主机 key 未存储在 sshknown_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'

注意事项,根据您的应用程序,这可能并不重要:

关于amazon-web-services - AWS EC2 : Safe way to get host public key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23331014/

相关文章:

java - 如何使用java读取S3中存在的JSON文件

ruby-on-rails - 如何为 aws ec2 ubuntu 服务器提供 Capistrano rails 3.1 应用程序部署的密码?

amazon-web-services - 将 Amazon AMI 移动到另一个账户

mysql - 在实例之间切换 ebs 卷

amazon-web-services - IAM 实例配置文件名称无效

amazon-web-services - EC2 安全组与 IAM 组?

amazon-web-services - DynamoDB 在分区键选择错误的 GSI 上读取是否会影响表的读/写

amazon-web-services - 在 amazon 为什么我不能从公共(public) ip 地址查看我的 tomcat?

python - Paramiko AuthenticationException 问题

git - 执行 ssh-add 并自动输入密码的脚本