【问题标题】:Copy SSH-keys between hosts在主机之间复制 SSH 密钥
【发布时间】:2016-05-02 20:00:02
【问题描述】:

我正在表演:

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

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

【问题讨论】:

  • 输入yes 会发生什么?
  • 我输入了是。但是权限仍然被拒绝。当我再次尝试时,它不会再次询问 ECDSA 密钥指纹,但仍会返回权限被拒绝

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


【解决方案1】:

尝试将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.pem 是 AWS 在您启动实例时附加到您的实例的密钥对的私有部分。

【讨论】:

  • 我用我的用户 centos 和 root 尝试过。但仍然是同样的问题。我尝试此循环的参考来自:docs.openshift.org/latest/install_config/install/…(在页面末尾)
  • 用户 centos 因为我的亚马逊 ec2 有 centos 作为操作系统
  • 因为这个问题,我没有为 ssh'n 使用 .pem-key。
  • 你用什么代替? @user5558501
【解决方案2】:

我使用这个脚本,它对我有用: Сan你试试这个

for host in ${hosts[*]}
do
echo $host
ssh-keyscan $host | tee -a ~/.ssh/known_hosts
sshpass -p 'mypass' ssh-copy-id myuser@$host
done

【讨论】:

  • 这在 AWS 上有效吗?它与aws有关的问题,根据其他答案,我认为AWS在ssh和密码方面存在一些问题。
猜你喜欢
  • 1970-01-01
  • 2021-08-26
  • 2018-09-13
  • 2021-03-22
  • 2020-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-16
相关资源
最近更新 更多