Transferring Files between two EC2 Instances in the same region
Assuming both of your instances are EC2 linux instances.
suppose you want to transfer file from the second instance(ec2-2) to first instance(ec2-1), the command should be run in ec2-1 is:
scp -i /Path-To-Key-File-for-ec2-2/key.pem ec2-user@Elastic-IP-of-ec2-2:/path/filename your/local-path-on-ec2-1/filename
A corresponding discussion you can find here
Hope this help!!
Actually, I figured it out ... I just needed to replace the Elastic IP with the private IP and configure the security groups properly to allow instances to communicate!
Transferring from Machine A to Machine B
I am running this code on machine A
scp -i ~/Path-To-Key-File/AAA.pem /path/file ec2-user@<Private IP of Machine B>:/path/file
For security groups, I had to allow SSH protocol over the private IP (from Machine B)!!
This question is asked about authentication with the .pem
file. But accessing without auth could be helpful in some cases. Here, you will authorize another machine instead.
Say, you like to ssh
or scp
from machine-1 to machine-2.
In machine-1.
- Check if there is a public key file (id_rsa.pub) in USER_HOME/.ssh/. If not, generate it with
ssh-keygen -t rsa
command.
In machine-2
- Uncomment
PubkeyAuthentication yes
in/etc/ssh/sshd_config
. - Open file
USER_HOME/.ssh/authorized_keys
and append contents ofid_rsa.pub
file from the machine-1.
Now you can copy it with scp
as following:
scp username_machine1@ip_machine1:/file/to/copy /destination/path
You are done. Enjoy!!!
For detailed information please check here.