bash - 在主机之间复制 SSH key

标签 bash amazon-web-services ssh-keys ssh-keygen

我正在表演:

# copy public key to other hosts
for host in ec2-master.eu-west-1.compute.amazonaws.com \
ec2xxx.compute.amazonaws.com \
ec2xxx.compute.amazonaws.com; \
do ssh-copy-id -i ~/.ssh/id_rsa.pub $host; \
done

因此,我尝试将在 ec2-master.eu-west-1.compute.amazonaws.com 上生成的 key 复制到其他服务器。 但我还是明白了

/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
The authenticity of host 'ec2xxx.eu-west-1.compute.amazonaws.com (10.0.xx.xx)' can't be established.
ECDSA key fingerprint is 3a:63xx:a6:19:xx:23:d1:xx:06:22:xx:a0:b9:8c:xx:cf.
Are you sure you want to continue connecting (yes/no)? 

所以我的许可被拒绝了。但我不知道为什么。我做错了什么?

最佳答案

尝试将 ssh-copy-id 命令更改为:

ssh-copy-id -i ~/.ssh/id_rsa.pub ec2-user@$host

(假设您使用的是 Amazon Linux - 如果您使用的是 Ubuntu,请使用 ubuntu 作为用户)

更新:

我认为问题可能是因为您尝试将新 key 复制到仅接受使用现有 key 登录的主机(不允许使用密码)。

我无法让它与 ssh-copy-id 一起使用,但您可以使用标准 ssh 命令来完成:

cat ~/.ssh/id_rsa.pub | ssh -i AWS_key.pem centos@$host "cat - >> ~/.ssh/authorized_keys"

其中 AWS_key.pem 是 AWS 在您启动实例时附加到您的实例的 key 对的私有(private)部分。

关于bash - 在主机之间复制 SSH key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35010744/

相关文章:

regex - AWK 如果在两行相似的行中没有找到模式,则打印找到模式的行

iOS AWS SNS : How does client confirm SNS Topic subscription?

linux - 在 Nodester 安装中丢失

linux - 将程序的输出重定向到旋转文件

angularjs - 是否可以使用 CloudFront 通过 SSL 在 Amazon S3 上托管 AngularJS 应用程序?

github - 在 GitHub 上为我的 ssh key 创建密码

linux - 如何从另一台 PC 进入 AWS 实例

c# - 使用 Bouncy CaSTLe 将 RSA 公钥转换为 RFC 4716 公钥

bash - 如何在 macOS 终端中退出 vim 后显示以前的 shell 命令?

amazon-web-services - AWS SQS 中缺少 s3 事件