Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rsync to Amazon Ec2 Instance

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,

like image 724
a53-416 Avatar asked Apr 05 '13 20:04

a53-416


People also ask

How do you sync two EC2 instances?

The simplest solution would probably to periodically run rsync to sync the changes on one host to another. There are also bidirectional tools similar to rsync, such as Unison. You could use lsyncd to monitor the filesystem, which starts Unison to then perform a sync.

How do I transfer files using rsync?

If you want to copy a file from one location to another within your system, you can do so by typing rsync followed by the source file name and the destination directory. Note: Instead of “/home/tin/file1. txt”, we can also type “file1” as we are currently working in the home directory.

What is rsync in SSH?

Rsync stands for "Remote Sync." The rsync command lets you transfer and synchronize data between different machines and directories. Using the Secure Shell (SSH) protocol, you can copy your files securely to another location. The rsync tool has many benefits when compared to other methods for copying files.

How do I rsync a directory in Linux?

You also have an empty directory called dir2 . To sync the contents of dir1 to dir2 on the same system, you will run rsync and use the -r flag, which stands for “recursive” and is necessary for directory syncing: rsync -r dir1/ dir2.


1 Answers

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.

like image 191
natxty Avatar answered Sep 19 '22 12:09

natxty