Transfer files to Ubuntu Linux EC2 instances using an SCP client from your computer
Tags: ec2, linux, scp
Published: 2023-08-13 23:45:07

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](https://github.com/awsmine/EC2_projects)** 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?](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-linux-inst-ssh.html)

# Steps for implementation to this project:



## 1. Create a Key Pair ***`temp-KP`***


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dccv5yywb1npy9d6l8ov.png)

- Create keypair

## 2. Create EC2 Security Group ***`launch-wizard-1`***

- inbound rules

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zb4f8p1vkz5rpm0dtxdt.png)

- outbound rules

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yo7j52j6hhvykc78dvck.png)


## 3. Create an EC2 Ubuntu instance ***`my-EC2`***


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t60c6llt9mlolo5pt71u.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/urxqdd34phsgemghkyk6.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1m385okk7or61z434t1.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mf3iez3a47cfroht5r6a.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhdyzlamylfvy51cnh1o.png)


- take defaults

- Launch instance

## 4. Get the public DNS name of the instance

- ***`ec2-44-212-72-45.compute-1.amazonaws.com`***
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6q27bqq3d264st2yhjuz.png)

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

 - login to your EC2 instance on a Ubuntu Linux server 



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jemzg5hjteya6tvg2x8a.png)

- create a file rev.txt
```
Hello! Welcome
:wq
```
- change permissions
```
chmod 777 rev.txt
chown ubuntu/ubuntu rev.txt
```

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

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

```
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
```
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.