Rsync to Amazon Ec2 Instance
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/* \
root@ec2-XX-XXX-XXX-XXX.us-west-2.compute.amazonaws.com:/var/www/html/
That seemed to do the trick.
Rsync to Amazon Linux EC2 instance - Permission deniend
For copying local files to EC2, the rsync command should be run on your local system, not on the EC2 instance.
The tilde (~) will not be shell expanded to your home directory if it is inside quotes. Try using $HOME instead.
If you are using sudo on the local side, then you probably want to use sudo on the remote (e.g., to copy over file ownerships). This can be done with the appropriate
--rsync-path
option.I recommend including the options
-SHAX
to more closely preserve the files on the target system.If "media" is supposed to be a subdirectory, then a trailing slash will help avoid some oddities if it does not currently exist.
End result:
sudo rsync -azv -SHAX --progress -e "ssh -i $HOME/.ssh/MyKeyPair.pem" \
--rsync-path "sudo rsync" \
~/Desktop/luffy.jpg \
ec2-user@xx.xx.xx.xxx:/home/ec2-user/myproject/mysite/mysite/media/
Here's an old article where I write about using rsync with EC2 instances. You can replace "ubuntu" with "ec2-user" for Amazon Linux.
http://alestic.com/2009/04/ubuntu-ec2-sudo-ssh-rsync
If this not solve your problem, please provide more details about what exact command you are running where and what exact error messages you are getting.
Rsync over ssh with key gets error EC2
rsync -avrz -e “ssh -i /Users/User/Downloads/key.pem” /
^ ^
You're not using the ASCII double quote character "
here. You're using some kind of open- and close-quote characters intended for typesetting. Your command is failing because the shell doesn't treat these characters as quote marks; rsync ends up trying to execute a program named “ssh
.
Replace the characters with ASCII double quotes:
rsync -avrz -e "ssh -i /Users/User/Downloads/key.pem" /
Sync files from one EC2 instance to another
You needn't use your EC2 keys to setup SSH between the two EC2 instances. Look at this guide - http://ask-leo.com/how_can_i_automate_an_sftp_transfer_between_two_servers.html .
Simple outline of the process is, lets say you want to transfer files from Server1 to Server2. You basically create a new key for your user on Server1 (note this is different from the key you downloaded to access your EC2 instance - Server1 in this case). Then load up the public part in Server2's authorized_keys and you should be able to setup SSH.
If the user that the rsync process is going to run under is not your user, then you will have to setup SSH keys for the user that the process will run under.
HTH
rsync between 2 AWS EC2 insatnces: cannot locate .pem file
When creating a Keypair in the Amazon EC2 management console, a keypair (.pem
file) is downloaded to your computer. This is the private key.
Creating a keypair in the console does not put the key on any existing Amazon EC2 instances. However, when launching a new instance, you can select a keypair and it will be added to the /home/ec2-user/.ssh/authorized_keys
file.
If you have the private key, you can generate a public key from the .pem file with:
ssh-keygen -y -f key.pem > key.pub
The public key should be placed in the destination computer's ~/.ssh/authorized_keys
file for destination user (which is ubuntu
in your command sample).
The private key should be used on the source computer (as per my-ubuntu-ec2.pem
in your code sample).
If you have lost the private key, you will need to generate a new one and replace the keys on the instances.
Rsync to Amazon Linux EC2 instance - failed: No such file or directory
I completed this task with Filezilla instead, easier to use.
Synchronizing Amazon EC2 with Rsync
I keep the /var/www of some web-servers synced by putting it under version control with Mercurial (but any version control system should work really).
Gives you more ability to track diffs and rollback than rsync would, but whether it's suitable probably depends on what your content actually is (large binary files with a rapid turnover would be bad).
If you go down this route, don't forget to configure some rewriting rules so the .hgrc folder (or equivalent) isn't visible.
Related Topics
@Reboot Is Not Working in Cron
How to Capture Network Packets Per Pid
How to Recursively Copy a Directory into Another and Replace Only the Files That Have Not Changed
Enable/Disable Tasks in Crontab by Bash/Shell
How to Tell If a File Is Older Than 30 Minutes from /Bin/Sh
Attach to a Processes Output for Viewing
Centos Through a Vm - No Urls in Mirrorlist
Grep from Tar.Gz Without Extracting [Faster One]
Thousands of Images, How to Organize the Directory Structure? (Linux)
Convert Bash 'Ls' Output to JSON Array
Device Tree Compiler Not Recognizes C Syntax for Include Files
Command Not Found via Ssh with Single Command, Found After Connecting to Terminal
Why Is Dd with the 'Direct' (O_Direct) Flag So Dramatically Faster
Bash Alias with Argument and Autocompletion