AWS EC2 — create EC2 instance and connect to it via SSH

Hemant
4 min readSep 10, 2023

--

In this article we will see steps to create AWS EC2 instance and connect it via SSH.

Amazon EC2

Amazon Elastic Compute Cloud is secure and resizable compute capacity provided by AWS for difference types of workloads.

In simple words, instead of having your own physical server we can spin up server of any capacity of storage and compute in AWS environment.

EC2 Instance Types

There are different types of instances provided by AWS and common ones are-

  1. General Purpose
  2. Compute Optimized
  3. Memory Optimized
  4. Storage Optimized

For Complete List check this link

AWS Account

You can signup for free tier account if you don’t already have an account with AWS. AWS provides free tier for 12 months for certain types of services and EC2 instances.

Creating EC2 Instance

  1. Login to AWS console. Initially Recently visited section will be blank.
console home

2. Go to Search bar and type EC2, Select the EC2 from available options as selected here -

Search Bar is on top left corner — type EC2 in it.

3. Click on Launch Instance button (Highlighted in Orange)

4. Provide name for instance — “userbook-app-instance”

5. Under option Application and OS Images (Amazon Machine Image), select Amazon Linux as selected in above image.

6. Create new key pair by click on highlighted button “Create new key pair”

Provide Key pair name — “ub-key-pair”

Click on Create key pair. File with name ub-key-pair.pem will be downloaded in your system.

This file will be used later to connect this EC2 instance via SSH

7. Change Network Settings — change setting as per below image

8. Now click on Launch Instance(In Orange) at right bottom corner

Instance should be ready after few seconds.

9. Click on instance ID from success message.

Alternatively we can use EC2 -> Instances

Now your instance is ready. It is time to connect to this instance.

Connect to EC2 instance via SSH

  1. Open Instance summary by click on Instance ID

2. Click Connect (in right) as shown above.

3. Connect to instance window will open with 4 tabs. Click SSH client tab.

4. Perform the steps as mentioned in your SSH client tab.

Step 1 — SSH client in your machine can be terminal, command line or any other tool like putty.

Step 2 — Go to folder from terminal where .pem file was downloaded.

Step 3 — Run command chmod 400 ub-key-pair.pem

Step 4 — Run command ssh -i “ub-key-pair.pem” <address from you ssh client window>

Below are example steps I performed using mac terminal.

Now you are connected to this instance.

Happy Learning.

--

--

Hemant

Lead Software Engineer @JPMorgan & Chase. Writes about Java, AWS and System Design