How to Create EC2 Instance (Ubuntu 22.04) on AWS and Connect Via SSH using PEM
Published: 2023-04-03 21:09:16


![img alt](https://media.giphy.com/media/5bvN6nytggNwpB4aZO/giphy.gif)
Hellooooo there,
Let me guess you have started your cloud journey and trying to find your way...right? same here :-)

We are going to set up our Instance or Virtual Machine if you prefer that. So, first things first ensure that you have a AWS account, You can set it up [here](https://aws.amazon.com/). 

## Table of Contents

- [Launch EC2 Instance](#Launch-EC2-Instance)

- [Configure Instance](#Configure-Instance)

- [Connect to Instance](#Connect-to-Instance)

- [Terminate Instance](#Terminate-Instance). 

## Launch EC2 Instance.

- 
Search for EC2 on the search bar then open it,on the **EC2 Dashboard** you will see Resources which shows the instances that are running and everything related to EC2.  

- 
 Under **Launch Instance** section there is the Launch Instance button that we'll use to create a new instance so click on it.

_Check the image below for reference_


![EC2 Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h1g2tmybvvalklpqrt58.png)

## Configure Instance.

- **Name and Tags**
You are going to give a name to your instance, 

- **Application and OS Images (Amazon Machine Image)**
Depending on the Operating system,application server and application you are dealing with you select AMI that suites you. _(Under the **Instance type** you'd want to leave it unchanged since we are using the free tier but there are so many options!)_

_Check the image below for reference_

![Name and AMI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hgsvzhryam3ufw6zx100.png)

- **Key pair (login)**

This is an essential part since it deals with security. If by chance you share your service IP  address they cannot access your server without any key.
We need to generate a key pair for our instance, so click in the _create new key pair_ and proceed to give the key pair name, type and key file format (if you are using Mac or Linux to log in to the server select .pem and use .ppk if you are using windows).
A file  with the key pair name will be downloaded to your device.(we'll use it later to connect to our instance do, so do)

_Check the image below for reference_


![Key Pair](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aewbphh0baucrjglyvwk.png)

- **Network Setting**
Keep the subnet as it is and enable auto-assign public IP- this will assign a public IP after starting the vm.

- **Create Security Group**
this controls traffic to the instance, you can leave it or customize it to your liking.

- **Configure storage**
The maximum storage for free tier is 30GB so feel free to adjust it accordingly.

_Check the image below for reference_


![Network and security](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2h8v2b1mf1wyjs174x2j.png)

- **Summary**

After finishing configuring everything you can select the number of instance you want created and click on the Launch Instance button to create it you'll then see the 
_'Successfully initiated launch of instance'_ 

![summary](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0khlq0wktpcgebskcdup.png)

## Connect to Instance
When you check the instances you'll be able to see a list of instances that you have including the one just created. 

Like so:

![Connect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m41j4cpgzopdrm3uknrn.png)

- Click on the check box under arrow 1 to view instance details.
- To connect to your EC2 instance from ubuntu, open your terminal and run this command ( I am assuming that you saved your key pair in your home). 

`ssh -i path-to-key ec2-user@ip-address`

_example_

`ssh -i "SCA-emerald.pem" ubuntu@ec2-18-219-91-204.us-east-2.compute.amazonaws.com
`
_Check the image below for reference_

![connect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/km6vl2wrpv8p9bojkn9q.png)



## Terminate Instance
- On the instance state under the instances page, there is a button named **Instance state** when you click on the drop down there is an option to 'terminate instance' which will redirect you to a confirmation page.
If you are sure you want to delete the instance then go ahead click the Terminate button!


We've come to end of this tutorial, until next time...

![end](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09en0gn01ibao9e8kaoy.jpg)