rsync 后权限被拒绝(公钥)

rsync 后权限被拒绝(公钥)

免责声明:这可能与 Ubuntu 并不完全相关,但由于某种原因,serverfault 在发布时给我一个错误,另外我想你们中的一些人可能以前偶然发现过类似的东西

我遇到了一个奇怪的问题。我管理着多个 ec2 实例,并且必须将一些隐藏文件从 Ubuntu 复制到 Amazon Linux 实例。

据我所知,应该使用 rsync,并且由于 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:

两者都成功了。

问题是,当我再次 ssh 到第二台机器(第一台机器没问题)时,出现了一个模糊的

Permission denied (publickey).

请注意,在 rsync 之前,连接没有问题,即使密钥文件损坏了,我也从备份中恢复了它,并处理了它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).

知道到底发生了什么吗?我完全不知道。

提前致谢

答案1

请注意,当使用 -a 传输到根文件夹时,Rsync 可能存在保护功能或错误。

给定一个包含 cow.txt 的本地文件夹,名为 Music

rsync -a Music/ [email protected]:/usr/ 

将音乐文件夹中的cow.txt文件移至usr/,我仍然可以登录。

rsync -a Music/ [email protected]:/root/ 

将 cow.txt 文件移动到 /root/ 中,授权密钥不受影响,但随后我无法使用[电子邮件保护]

我不确定为什么会发生这种情况,并且在服务器日志中看不到任何可以解释这种情况的内容。

但至少可以很容易地避免这个问题

远程和本地服务器均运行 rsync 版本 3.1.1 协议版本 31

在 Ubuntu 16.04 上

答案2

rsync命令使用第一个远程主机中的文件夹 内容覆盖ssh 第二个远程主机 /home/username/ 中的配置.ssh.ssh

确认的方法是:

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

相关内容