rsync后权限被拒绝(publickey)

免责声明:这可能与Ubuntu没有完全相关,但由于某种原因,serverfault在发布时给我一个错误,而且我认为你们中的一些人可能偶然发现过这样的事情。

我遇到了一个奇怪的问题。 我有多个我正在管理的ec2实例,我不得不将一些隐藏文件从Ubuntu复制到Amazon Linux实例。

要走的路应该是rsync AFAIK,因为pem文件在我的本地机器上 – Mac OS X 10.10.5 – 我做了我必须做的事情:

rsync -rave "ssh -i keyfile1.pem" ubuntu@firstmachineip:folder_inside_home/ local_folder/ 

然后

 rsync -rave "ssh -i keyfile2.pem" local_folder/ ec2-user@secondmachineip: 

两者都成功了。

问题是当再次sshing到第二台机器(第一台很好)给我模糊

 Permission denied (publickey). 

请注意,在rsyncing之前连接没有问题,即使密钥文件已损坏,我还是从备份恢复它并处理chmod 600 keyfile2.pem甚至尝试了chmod 400 keyfile2.pem

在确定指纹已知之后,我还将保留ssh -vvv -i keyfile2.pem ec2-user@secondmachineip输出的最后一部分:

 debug1: Host 'secondmachineip' is known and matches the RSA host key. debug1: Found key in /Users/thevet/.ssh/known_hosts:10 debug2: bits set: 494/1024 debug1: ssh_rsa_verify: signature correct debug2: kex_derive_keys debug2: set_newkeys: mode 1 debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug2: set_newkeys: mode 0 debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug2: service_accept: ssh-userauth debug1: SSH2_MSG_SERVICE_ACCEPT received debug2: key: keyfile2.pem (0x0), explicit debug1: Authentications that can continue: publickey debug3: start over, passed a different list publickey debug3: preferred publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Trying private key: keyfile2.pem debug1: read PEM private key done: type RSA debug3: sign_and_send_pubkey: RSA *here goes the rsa* debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey debug2: we did not send a packet, disable method debug1: No more authentication methods to try. Permission denied (publickey). 

到底发生了什么事? 我很无能为力。

提前致谢

rsync命令覆盖第二个远程主机/ home / username / .sshssh配置,其中包含来自第一个远程主机的.ssh文件夹的内容

确认它的方法是:

  • 从firstmachineip复制(使用rsync)到local_folder
  • 从local_folder中删除.ssh文件夹
  • 从local_folder复制(使用rsync)到secondmachineip