我正在表演:
# 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/