Rsync to Amazon Ec2 Instance

LinuxSshAmazon Ec2Rsync

Linux Problem Overview


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]2.compute.amazonaws.com:/var/www/html/

Thanks,

Linux Solutions


Solution 1 - Linux

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

ssh -i ~/path/mykeypair.pem \
ubuntu@ec2-XX-XXX-XXX-XXX.us-west-2.compute.amazonaws.com

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]2.compute.amazonaws.com:/var/www/html/

That seemed to do the trick.

Solution 2 - Linux

Below is what I used and it worked. Source was ec2 and target was home machine.

 sudo rsync  -azvv -e "ssh -i /home/ubuntu/key-to-ec2.pem" ec2-user@xx.xxx.xxx.xx:/home/ec2-user/source/ /home/ubuntu/target/

Solution 3 - Linux

After suffering a little bit, I believe this will help:

I am using the below command and it has worked without problems:

rsync -av --progress -e ssh /folder1/folder2/* [email protected]:/folder1/folder2

First consideration:

Use the --rsync-path

I prefer in a shell script:

#!/bin/bash

RSYNC = /usr/bin/rsync

$RSYNC [options] [source] [destination]

Second consideration:

Create a publick key by command below for communication between the servers in question. She will not be the same as provided by Amazon.

ssh-keygen -t rsa

Do not forget to enable permission on the target server in /etc/ssh/sshd_config (UBUNTU and CENTOS).

https://stackoverflow.com/questions/6963740/sync-files-from-one-ec2-instance-to-another

http://ask-leo.com/how_can_i_automate_an_sftp_transfer_between_two_servers.html

Use -v option for verbose and better identify errors.

Third Consideration

If both servers are on EC2 make a restraint by security group

In the security group Server Destination:

inbound: Source / TCP port 22 / IP Security (or group name) of the source server

Solution 4 - Linux

copy file from local machine to server

rsync -avz -e "ssh -i /path/to/key.pem" /path/to/file.txt  <username>@<ip/domain>:/path/to/directory/

copy file from server to local machine

rsync -avz -e "ssh -i /path/to/key.pem" <username>@<ip/domain>:/path/to/directory/file.txt  /path/to/directory/

Solution 5 - Linux

This worked for me:

nohup rsync -zravu --partial --progress  -e "ssh -i xxxx.pem" [email protected]:/mnt/data   /mnt2/ &

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiona53-416View Question on Stackoverflow
Solution 1 - LinuxnatxtyView Answer on Stackoverflow
Solution 2 - LinuxDeepti KohliView Answer on Stackoverflow
Solution 3 - LinuxrmsysView Answer on Stackoverflow
Solution 4 - Linuxanjaneyulubatta505View Answer on Stackoverflow
Solution 5 - LinuxHARSHView Answer on Stackoverflow