How to Launch an EC2 Instance: Create a Key Pair and Configure Security Group

Launch EC2 Instance Introduction:

Amazon EC2 (Elastic Compute Cloud) is a fundamental cloud computing service and represents virtual cloud computers with availability. To Launch an EC2 Instance.

  1. Start an instance
  2. Create a key pair
  3. Configure a security group
  4. To connect to the instance we will use SSH

This leads to the fact that you can work in a cloud computing environment with maximal protection.

Launch EC2 Instance Objective:

Launch an EC2 Instance With the help of Git Bash launch an instance of the EC2, create a key pair, set up a security group that allows all traffic, connect to the instance, and shut it down at the end.

Launch EC2 Instance Prerequisites:

  1. AWS account.
  2. There is an install of Git Bash on your laptop.
  3. familiar with the AWS EC2 concept.
ALSO READ: 

Steps to Launch an EC2 Instance

1. Create a Key Pair Using Git Bash

  • Open Git Bash on your laptop.

Run the following command to generate a new key pair:

ssh-keygen -f krishna_aws
  • Copy the content of the public key file:
  1. Cat ec2-keypair.pub
  2. Log in to the AWS Management Console
  3. Navigate to EC2 Dashboard > Key Pairs > Create Key Pair
  4. Choose Import Key Pair, provide a name, and paste the copied public key.

Launch an EC2 Instance ssh key

2. Configure a Security Group

  1. In the EC2 Dashboard, go to Security Groups > Create Security Group.
  2. Provide a name and description.
  3. Under Inbound Rules, add the following:
    • Type: All Traffic
    • Protocol: All
    • Port Range: 0-65535
    • Source: 0.0.0.0/0 (for all IPs)

Note: Allowing all traffic is not recommended for production environments.

Save the security group.

Launch an EC2 Instance Import key configuration

3. Launch an EC2 Instance

  1. Navigate to Instances > Launch Instances.
  2. Configure the following:
    • Name: Provide a name for the instance.
    • AMI: Select an Amazon Machine Image (e.g., Amazon Linux 2).
    • Instance Type: Choose a type (e.g., t2.micro for free tier).
    • Key Pair: Select the key pair created earlier.
    • Security Group: Select the security group created earlier.
  3. Click Launch Instance
  4. Wait for the instance to initialize.

Launch an EC2 Instance 2

Launch an EC2 Instance 2

Launch an EC2 Instance 3

4. Connect to the EC2 Instance

  1. Copy the public IP address of the instance.

Open Git Bash and run:

ssh -i krishna_aws ec2-user@44.202.92.44
  1. Replace <PUBLIC_IP> with the instance’s public IP.
  2. You will be connected to the EC2 instance.

5. Shutdown and Delete the EC2 Instance

To shutdown the instance:
sudo shutdown -h now

  1. In the AWS Management Console, navigate to Instances.
  2. Select the instance and click Instance State > Terminate Instance.
  3. Confirm the termination.

Now we can successfully  Launch an EC2 Instance : Create a Key Pair and Configure Security Group

Thank You

Leave a Comment