Srce Cde
Published in

Srce Cde

Copy file | directory to & from EC2 using SCP (Secure copy)

scp ec2 instance
Photo by Clark Van Der Beken on Unsplash

While we are working with EC2 Linux instances we might require to transfer files from the local system to the EC2 instance quickly. Obviously, there are a couple of ways to achieve this but one of the ways that can come in handy is to use the Secure copy protocol.

Secure Copy protocol allows you to transfer files securely between two hosts. It uses same underlying protocol as SSH. Assuming that you have the instance up and running and have the identity file (.pem) handy since we will need the identity file to successfully copy file/directory to & from EC2 instance. Make sure you have port 22 open.

To copy the file from local machine to EC2 instance:

  • Open local terminal
  • scp -i identity_file.pem source_file.extention username@public_ipv4_dns:/remote_path
Ex: scp -i access.pem ~/Documents/temp_file.txt ubuntu@0.0.0.0:/home/ubuntu/destination_dir

scp: Secure copy protocol
-i: Identity file
source_file.extension: The file that you want to copy
username: Username of the remote system (ubuntu for Ubuntu AMI & ec2-user for Linux AMI)
public_ipv4_dns: DNS/IPv4 address of an instance
remote_path: Destination path

To copy the file from EC2 instance to local machine:

  • Open local terminal
  • scp -i identity_file.pem username@public_ipv4_dns:/remote_path/source_file.extension ~/destination_local_path
Ex: scp -i access.pem ubuntu@0.0.0.0:/home/ubuntu/remote_path/temp.txt ~/Documents/destination_dir

To copy the directory from local machine to EC2 instance:

  • Open local terminal
  • scp -i identity_file.pem -r source_dir username@public_ipv4_dns:/remote_dir_path
Ex: scp -i access.pem -r ~/Documents/directory1 ubuntu@0.0.0.0:/home/ubuntu/

-r: Recursively copy entire directory

To copy the directory from EC2 instance to local machine:

  • Open local terminal
  • scp -i identity_file.pem -r username@public_ipv4_dns:/remote_dir_path destination_dir
Ex: scp -i access.pem -r ubuntu@0.0.0.0:/home/ubuntu/source_dir ~/Documents/directory1

You can optionally refer this video tutorial on the same.

If you enjoyed this article, you might want to check out other articles. Follow me and my publication on Medium for the latest updates.

All about you need to know. The purpose of sharing the knowledge. Know more learn more. The blog that will help you learn, know and implement.

Recommended from Medium

Quick Tip: How to save spaCy dependency graphs as png

This is part 2 of the reverse engineering ippsRSA library to induce faults.

Key features to look at from a system integrator in 2022

WFS 3.0 Hackathon Results

GemUni project starts sales on Liquidifty.io!

How to Integrate PayPal payment Gateway to your Website

Stream Chat and API-Driven Telemedicine Services

FPGA BASED IMAGE PROCESSING UNIT

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Srce Cde

Srce Cde

AWS Community Builder | YouTuber: https://youtube.com/srcecde

More from Medium

Configure Web Server on AWS Cloud

AWS: Use PuTTY to login to EC2 instance

How to create a Text To Speech API using `pyttsx3` library?

Remote connect AWS windows EC2 without exposing public IP with Omniedge