Rsync to Amazon Ec2 Instance

a53-416 picture a53-416 · Apr 5, 2013 · Viewed 48.7k times · Source

I have an EC2 instance running and I am able to SSH into it.

However, when I try to rsync, it gives me the error Permission denied (publickey).

The command I'm using is:

rsync -avL --progress -e ssh -i ~/mykeypair.pem ~/Sites/my_site/* [email protected]:/var/www/html/

I also tried

rsync -avz ~/Sites/mysite/* -e "ssh -i ~/.ssh/id_rsa.pub" [email protected]:/var/www/html/

Thanks,

Answer

natxty picture natxty · Apr 25, 2013

I just received that same error. I had been consistently able to ssh with:

ssh -i ~/path/mykeypair.pem \
[email protected]

But when using the longer rsync construction, it seemed to cause errors. I ended up encasing the ssh statement in quotations and using the full path to the key. In your example:

rsync -avL --progress -e "ssh -i /path/to/mykeypair.pem" \
       ~/Sites/my_site/* \ 
       [email protected]:/var/www/html/

That seemed to do the trick.