Create a Virtual Machine Instance(EC2) in AWS & Connect Via SSH(Cloudshell)
Tags: scacloudschool, cloudpractitioner, awscloushell, ec2
Published: 2023-05-07 01:06:35

## **What is an EC2?**

An EC2 (Elastic Compute Cloud) is a virtual computing environment provided by Amazon Web Services (AWS). It allows you to create and manage virtual machines (instances) in the cloud.

## **How can you use an EC2?**

You can use an EC2 to run your applications, services, or workloads in the cloud. You can choose the hardware specifications (CPU, memory, storage) and the operating system of your instances, and you only pay for the resources you use.

By the end of this tutorial you should be able to accomplish the following:

- Create EC2 instance
- SSH into EC2 Virtual Instance Machine using Cloudshell


**What you'll need to get started:**
- An AWS account 
- SSH Client(Cloudshell) 

Now let's get started and create an EC2 instance:

## **Step 1:**
 
**Sign into the [AWS Management Console]**(https://aws.amazon.com/console/)


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

## **Step 2:**
**Navigate to the EC2 Dashboard** ( **search for EC2** )

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7x4gcfesk7stz0b7bwhk.PNG)

## **Step 3:**
**Click on Instance**

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

## **Step 4:**
**Click on the "Launch Instance" button.**


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

## **Step 5:**
**Name your EC2 Instance:**

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

## **Step 6:**
**Choose an Amazon Machine Image (AMI)**
An AMI is a pre-configured image that contains the software and operating system you want to use on your instance.

We'll use AWS Linux in this tutorial


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

## **Step 7:**
**Select an Instance Type**
An Instance Type determines the hardware specifications of your virtual machine, such as CPU, memory, and storage.

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

## **Step 8:**
**Create a key pair**
A key pair is a set of public and private keys that allows you to securely connect to your instance over SSH.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mugj3iqp90hqb1ss7va.PNG)

## **Step 9:**
Configure the **Network** Instance Details, such as the **VPC** settings, the **subnet**.

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

Configure **Security Group** settings to allow inbound traffic to your instance.

You can add rules to your security group to **allow access** over specific ports or protocols, such as SSH or HTTP.

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

## **Step 10:**
**Add Storage to your instance**
You can choose the storage type (such as SSD or HDD), size, and number of volumes. You can add up 30GB on the free tier account


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7b203thuidghs6pe48rs.PNG)


**Review Summary**
A summary of your configurations will be displaced you can also select the number of instances you'd like, if you're happy with everything you can **click on launch**

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

## **Step 11:**
**Launch your instance and connect**

After a few minutes, your virtual machine will be launched and ready to use.

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

_You've successfully created a virtual machine (EC2) in AWS._ 

You can now **connect** to your instance by following the steps below:
**1. Click on the check box **
**2. Click on connect**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4eljmeeu9p8lgz51bi8m.PNG)

## Connect using SSH client

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

**Open an SSH client**
In the AWS Management Console, at the top of the screen, choose the AWS CloudShell icon

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

**Locate your private key file**.
The key used to launch this instance is `sips.pem`


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

**Run this command**
To ensure your key is not publicly viewable.
 `chmod 400 sips.pem`

**Connect to your instance** 
using its Public DNS:
`ec2-3-90-208-38.compute-1.amazonaws.com`

**Run command:**

 `ssh -i "sips.pem" ec2-user@ec2-3-90-208-38.compute-1.amazonaws.com`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6khfm7vhth7n9x7t9fb7.PNG)

Voila! You've successfully created a virtual machine (EC2) in AWS and used AWS cloudshell to SSH into it.