Securely transfer files between 2 EC2 instances using SCP

Photo by Andrew Neel on Unsplash

Securely transfer files between 2 EC2 instances using SCP

Using SCP we transfer files between 2 systems.

SCP - Server Copy Protocol

To transfer files between 2 EC2 instances, let's say Instance - A wants to send a file to Instance - B, so Instance - A should have pem file of Instance - B & vice - versa.

So, here we're using WSL to access these instances, & on our machine, we have the pem files of both instances.

Using SSH we can log into these instances ( ssh -i pem file ubuntu@Public IP 4 DNS name ) & by using SCP we can send the pem file of instance B to instance A.

Note:-

  • Ensure to change the permission of Instance - B.pem to (chmod 444 filename), otherwise, you'll get an error.
  • Get the Public IP of the instance using the command curl ifconfig.me on that instance.

scp -i Instance - A.pem Instance-B.pem ubuntu@Public-IP:~

Now Instance - A has B's pem file, Now change the permissions again of Instance - B pem file to (chmod 400 file-name) & then -

scp -i Instance - B.pem sayHello.txt ubuntu@Public-IP:~

  • ~ stands for Home directory, If you want to put the file in some directory, then you have to put the PATH to that directory.

  • SayHello.txt is the file we want to send to Instance - B.