Sometimes, we need to copy, migrate or transfer files between instances for multiple reasons. In this tutorial, I am going to share a very simple method to copy files between EC2 Instances in AWS(Amazon Web Services). So, let’s get started.
Copy Files from one EC2 to another EC2 instance
Suppose, you have to copy files from EC2 instance A to EC2 instance B. To copy files between the servers, you need to use SCP(Secure Copy Files) to copy the files. Let me explain how. I am taking to two instance to demonstrate the steps.
Pre-requisites
- IP address of the both EC2 instance.
- SSH keys for the EC2 instance.
Step 1: Upload the SSH key of the EC2 instance
I am assuming that you are copying files from EC2 instance A to EC2 instance B. To transfer files between two instances, you have to upload the ssh key of instance B to instance A or instance A to instance B vice-versa. To upload ssh keys use the SCP command as below.
$ scp -i "instance_A_sshkey" "instance_B_sshkey" "ec2_instance_username"@"instance_A_I
Example:
$ scp -i ec2_instance_A.pem ec2_instance_B.pem ubuntu@65.0.81.134:~
When you run this command, it will upload the SSH key of the EC2 instance B to the EC2 instance A
Step 2: SSH into the EC2 instance A to Copy Files between EC2 Instances
Now, ssh into the EC2 instance A, to copy your files to EC2 instance B.
ssh -i ec2_instance_A.pem ubuntu@12.34.56.78
After login to EC2 instance A, run following command to list the files.
ls
Output
ec2_instance_B.pem file.zip
Let’s transfer the file zip to the instance B from instance A by following command.
scp -i ec2_instance_B.pem file.zip ubuntu@13.232.43.90:~
You transfer is complete now.
Step 3: SSH into the EC2 instance B to check the file
Login to the EC2 instance B to check the transferred file. It should be on the home directory.
Read More: How to Install WordPress on AWS EC2 in 10min
Conclusion
In this short tutorial, you have learned to copy files between EC2 Instances. If you have any doubts feel free to contact me, I will definitely try to help you. Also, you can join our elite Facebook group to get direct help from me. If you like this tutorial, please share this article on your social media handle.