Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transferring Files between two EC2 Instances in the same region

I have 2 EC2 instances running Ubuntu 14.04 and I need to figure out how to transfer files from one to another. I read the FAQs from Amazon and it says that I can do this without incurring any additional costs if I use the private IP but I am not sure how to transfer the files using that.

Right now I use the scp protocol to do this -

scp -i ~/Path-To-Key-File/AAA.gem /path/file  ec2-user@<Elastic IP>:/path/file

I tried replacing the elastic IP with private IP but it doesn't work. Am I doing something wrong here?

like image 703
Kshitiz Avatar asked Aug 20 '14 12:08

Kshitiz


3 Answers

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)!!

like image 180
Kshitiz Avatar answered Oct 05 '22 23:10

Kshitiz


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!!

like image 22
Tapaswi Panda Avatar answered Oct 05 '22 22:10

Tapaswi Panda


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 of id_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.

like image 4
misbah Avatar answered Oct 05 '22 23:10

misbah