Rsync to EC2: Identity file not accessible

amazon ec2file-transferrsync

I'm trying to rsync a file over to my EC2 instance:

 rsync -Paz --rsh "ssh -i ~/.ssh/myfile.pem" --rsync-path "sudo rsync" file.pdf ubuntu@ec2-XXX-XX-XX-X.compute-1.amazonaws.com:/home/ubuntu/

This gives the following error message:

Warning: Identity file ~/.ssh/myfile.pem not accessible: No such file or directory.
ubuntu@ec2-XXX-XX-XX-X.compute-1.amazonaws.com's password: 

The pem file is definitely located at the path ~/.ssh/myfile.pem, though: vi ~/.ssh/myfile.pem shows me the file.

If I remove the remote path from the very end of the rsync command:

rsync -Paz --rsh "ssh -i ~/.ssh/myfile.pem" --rsync-path "sudo rsync" file.pdf ubuntu@ec2-XXX-XX-XX-X.compute-1.amazonaws.com

Then the command appears to work…

building file list ... 
1 file to consider
file.pdf
       41985 100%    8.79MB/s    0:00:00 (xfer#1, to-check=0/1)
sent 41795 bytes  received 42 bytes  83674.00 bytes/sec
total size is 41985  speedup is 1.00

…but when I go to the remote server, nothing has actually been transferred.

What am I doing wrong?

Best Answer

--rsync-path "sudo rsync"

This makes rsync to run by privileged user (root), so ~/ is path for home directory of root. If you omit this part of code it should work.

PS. scp is working, because you run it using your normal account.

PS2. Removing remote path also work, but this does not send anything through the network, but just copy the file "file.pdf" to file with name ubuntu@ec2-XXX-XX-XX-X.compute-1.amazonaws.com (see with ls -l)

Related Topic