DEV Community

Cover image for How to Create EC2 Instance (Ubuntu 22.04) on AWS and Connect Via SSH using PEM
Ivy Jeptoo
Ivy Jeptoo

Posted on • Updated on

How to Create EC2 Instance (Ubuntu 22.04) on AWS and Connect Via SSH using PEM

img alt
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.

Table of Contents

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

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

  • 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

  • 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

  • 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

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

  • 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

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

Top comments (4)

Collapse
 
arbythecoder profile image
Arbythecoder

welldone ivy,thank you

Collapse
 
jeptoo profile image
Ivy Jeptoo

Much appreciate

Collapse
 
chymee profile image
Amadi Chimeremma

good job ivy!

Collapse
 
jeptoo profile image
Ivy Jeptoo

Thank you Chime