rsync到EC2使用ssh -i

我能够ssh -i mykey.pem到EC2。 我能scp -i mykey.pem到EC2。 但是,当我尝试rsync -avz -e "ssh -i mykey.pem"我得到这个错误:

 Warning: Identity file mykey.pem not accessible: No such file or directory. Permission denied (publickey). rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(605) [sender=3.0.9] 

任何build议我做错了?

确保.pem文件确实在你的想法。

尝试rsync -avz -e "ssh -i ./mykey.pem"使用./

注意:对于这个例子,你的.pem必须在当前的工作目录中。 如果在其他地方,则将其更改为使用绝对path( /home/me/path/to/file.pem

作为一个debugging的angular度,尝试在你的shell会话中运行ssh-agent , 就像在这个SO回答中所描述的类似的问题一样 。 基本上,你在本地运行ssh-agent ,添加你的密钥,然后看看rsync是否正确地select它。 这个想法是要消除一些其他的错误,希望能提供一些洞察真正的问题(因为我们已经在评论中干了)。

命令string是这样的:

 eval $(ssh-agent) ssh-add path/to/mykey.pem rsync -avz localfile remoteuser@ec2-instance:/remotelocation 

这在我的环境中可以访问我的AWS系统。