DEV Community

Revathi Joshi for AWS Community Builders

Posted on

Transfer files to Ubuntu Linux EC2 instances using an SCP client from your computer

In this article, I am going to show you how to transfer files between your local computer and a Linux instance using secure copy protocol (SCP).

Please visit my GitHub Repository for EC2 articles on various topics being updated on constant basis.

Let’s get started!

Objectives:

1. Create a Key Pair temp-KP

2. Create EC2 Security Group launch-wizard-1

3. Create an EC2 Ubuntu instance my-EC2

4. Get the public DNS name of the instance

5. Use SCP to transfer files between your computer to your instance

Pre-requisites:

  • AWS user account with admin access, not a root account.

Resources Used:

What is Amazon EC2?

Steps for implementation to this project:

1. Create a Key Pair temp-KP

Image description

  • Create keypair

2. Create EC2 Security Group launch-wizard-1

  • inbound rules

Image description

  • outbound rules

Image description

3. Create an EC2 Ubuntu instance my-EC2

Image description

Image description

Image description

Image description

Image description

  • take defaults

  • Launch instance

4. Get the public DNS name of the instance

  • ec2-44-212-72-45.compute-1.amazonaws.com Image description

5. Use SCP to transfer files between your computer to your instance

  • login to your EC2 instance on a Ubuntu Linux server

Image description

  • create a file rev.txt ```

Hello! Welcome
:wq

- change permissions
Enter fullscreen mode Exit fullscreen mode

chmod 777 rev.txt
chown ubuntu/ubuntu rev.txt


- change permissions to your key-pair ***`temp-KP.pem`***

Enter fullscreen mode Exit fullscreen mode

revjoshi@DESKTOP-9HCK7TO:~$ chmod 400 temp-KP.pem
revjoshi@DESKTOP-9HCK7TO:~$ ls -lt temp-KP.pem
-r-------- 1 revjoshi revjoshi 1674 Aug 13 17:40 temp-KP.pem
revjoshi@DESKTOP-9HCK7TO:~$

- make a directory ***`revjoshi1`***

- (Public DNS) To transfer a file to the destination on the instance

Enter fullscreen mode Exit fullscreen mode

revjoshi@DESKTOP-9HCK7TO:~$ scp -i "temp-KP.pem" /home/revjoshi/rev.txt ubuntu@ec2-44-212-72-45.compute-1.amazonaws.com:/home/ubuntu/
rev.txt 100% 15 0.9KB/s 00:00
revjoshi@DESKTOP-9HCK7TO:~$


- login to EC2 to check
Enter fullscreen mode Exit fullscreen mode

ssh -i "temp-KP.pem" ubuntu@ec2-44-212-72-45.compute-1.amazonaws.com

ubuntu@ip-172-31-88-165:~$ ls -lt
total 4
-rwxrwxr-x 1 ubuntu ubuntu 15 Aug 13 23:04 rev.txt
ubuntu@ip-172-31-88-165:~$


## Cleanup

- delete EC2 instance

## What we have done so far

Using SCP, we have successfully transferred a file using the instance's public DNS name from your computer to an EC2 instance.

Enter fullscreen mode Exit fullscreen mode

Top comments (0)