1

我正在表演:

# 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 上生成的密钥复制到其他服务器。但我仍然得到

/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)? 

所以我得到了一个被拒绝的权限。但我不知道为什么。我究竟做错了什么?

4

2 回答 2

0

我使用这个脚本,它对我有用:Сan you try this

for host in ${hosts[*]}
do
echo $host
ssh-keyscan $host | tee -a ~/.ssh/known_hosts
sshpass -p 'mypass' ssh-copy-id myuser@$host
done
于 2016-01-26T14:46:00.340 回答
0

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

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

(假设您使用的是 Amazon Linux——ubuntu如果您使用的是 Ubuntu,请以用户身份使用)

更新:

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

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

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

AWS_key.pemAWS 在您启动实例时附加到您的实例的密钥对的私有部分在哪里。

于 2016-01-26T09:43:20.487 回答