Launch and Configure an EC2 Instance( Step-by-Step EC2 Setup + SSH Connection (Windows)

Introduction Launching an EC2 instance is one of the first and most crucial steps when working with Amazon Web Services (AWS). It allows you to run virtual servers in the cloud, providing you with flexibility and scalability. In this tutorial, we’ll go step-by-step to launch an EC2 instance and connect to it via SSH using Windows. This guide is designed for beginners, so even if you're just starting out with AWS, you'll be able to follow along easily. Let’s dive into how to launch your first EC2 instance and establish an SSH connection. ✅ Step 1: Launch a New EC2 Instance Go to the EC2 Dashboard: Open the EC2 console by visiting EC2 Dashboard. Click “Launch Instance”: On the EC2 dashboard, find and click the Launch Instance button to start the process of creating a new instance. Configure the Instance: Name your instance: This is for identification purposes. You can name your instance anything you'd like (e.g., Durga-EC2). Choose an Amazon Machine Image (AMI): For simplicity, we’ll choose Amazon Linux 2 AMI (HVM), SSD Volume Type, which is free-tier eligible and suitable for most use cases. Select Instance Type: Choose t2.micro (Free tier eligible) for a low-cost option. This instance type is great for lightweight workloads. Configure Key Pair: Key Pair (login): Here, you can either choose an existing key pair or create a new one. For this guide, let’s create a new key pair with any name you like (e.g., my-key-pair). Key Pair Type: Select .pem. Download the key pair: Ensure that you download and save the .pem file in a safe location (e.g., C:\Users\Durga V\Downloads\my-key-pair.pem). You’ll need this file later to connect to your instance securely. Network Settings: Click “Edit inbound rules” and add a new rule to allow SSH access: Type: SSH Port: 22 Source: Anywhere (0.0.0.0/0), which allows access from any IP address (you can adjust this for more security if needed). Launch the Instance: After configuring the settings, click “Launch Instance” to create your EC2 instance. ✅ Step 2: Verify Instance Is Running Once the instance is launched: Go to Instances in the EC2 console. Find your instance in the list and verify that: ✅ Instance State = Running ✅ The Public IPv4 or DNS name is visible (you’ll need this to connect via SSH). ✅ Step 3: Open Git Bash (Not CMD) Windows users should use Git Bash for the SSH connection process. Git Bash is a terminal emulator that supports the necessary Linux commands for SSH. Open Git Bash: Press the Start menu, search for Git Bash, and open it. Navigate to the Folder: Use the cd command to change the directory to where you saved the .pem key pair file: cd "/c/Users/Durga V/Downloads" ✅ Step 4: Fix File Permission (Only Once) Before connecting via SSH, ensure your key file has the correct permissions by running: chmod 400 my-key-pair.pem This command ensures that your key file is only readable by you, which is a requirement for secure SSH connections. ✅ Step 5: Connect to the EC2 Instance via SSH Now, it’s time to connect to your EC2 instance using the SSH protocol. Use the SSH Command: In Git Bash, replace ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com with your instance’s Public IPv4 DNS (or IP address). The general SSH command looks like this: ssh -i "my-key-pair.pem" ec2-user@ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com Or you can use the public IP: ssh -i "my-key-pair.pem" ec2-user@ Accept the Security Warning: The first time you connect, you may see a warning about the authenticity of the host. Type yes to accept and proceed. Login: If everything is set up correctly, you’ll be connected to your EC2 instance and be presented with a terminal prompt for the ec2-user account. Cleanup or delete the instance:

Apr 18, 2025 - 08:19
 0
Launch and Configure an EC2 Instance( Step-by-Step EC2 Setup + SSH Connection (Windows)

Introduction

Launching an EC2 instance is one of the first and most crucial steps when working with Amazon Web Services (AWS). It allows you to run virtual servers in the cloud, providing you with flexibility and scalability. In this tutorial, we’ll go step-by-step to launch an EC2 instance and connect to it via SSH using Windows. This guide is designed for beginners, so even if you're just starting out with AWS, you'll be able to follow along easily.

Let’s dive into how to launch your first EC2 instance and establish an SSH connection.

✅ Step 1: Launch a New EC2 Instance

  1. Go to the EC2 Dashboard:
    Open the EC2 console by visiting EC2 Dashboard.

  2. Click “Launch Instance”:
    On the EC2 dashboard, find and click the Launch Instance button to start the process of creating a new instance.

  3. Configure the Instance:

    • Name your instance: This is for identification purposes. You can name your instance anything you'd like (e.g., Durga-EC2).
    • Choose an Amazon Machine Image (AMI): For simplicity, we’ll choose Amazon Linux 2 AMI (HVM), SSD Volume Type, which is free-tier eligible and suitable for most use cases.
    • Select Instance Type: Choose t2.micro (Free tier eligible) for a low-cost option. This instance type is great for lightweight workloads.
    • Configure Key Pair:
      • Key Pair (login): Here, you can either choose an existing key pair or create a new one. For this guide, let’s create a new key pair with any name you like (e.g., my-key-pair).
      • Key Pair Type: Select .pem.
      • Download the key pair: Ensure that you download and save the .pem file in a safe location (e.g., C:\Users\Durga V\Downloads\my-key-pair.pem). You’ll need this file later to connect to your instance securely.
    • Network Settings:
      • Click “Edit inbound rules” and add a new rule to allow SSH access:
      • Type: SSH
      • Port: 22
      • Source: Anywhere (0.0.0.0/0), which allows access from any IP address (you can adjust this for more security if needed).
  4. Launch the Instance:
    After configuring the settings, click “Launch Instance” to create your EC2 instance.

Image description

✅ Step 2: Verify Instance Is Running

Once the instance is launched:

  1. Go to Instances in the EC2 console.
  2. Find your instance in the list and verify that:
    • Instance State = Running
    • ✅ The Public IPv4 or DNS name is visible (you’ll need this to connect via SSH).

✅ Step 3: Open Git Bash (Not CMD)

Windows users should use Git Bash for the SSH connection process. Git Bash is a terminal emulator that supports the necessary Linux commands for SSH.

  1. Open Git Bash:

    • Press the Start menu, search for Git Bash, and open it.
  2. Navigate to the Folder:
    Use the cd command to change the directory to where you saved the .pem key pair file:

   cd "/c/Users/Durga V/Downloads"

✅ Step 4: Fix File Permission (Only Once)

Before connecting via SSH, ensure your key file has the correct permissions by running:

chmod 400 my-key-pair.pem

This command ensures that your key file is only readable by you, which is a requirement for secure SSH connections.

Image description

✅ Step 5: Connect to the EC2 Instance via SSH

Now, it’s time to connect to your EC2 instance using the SSH protocol.

  1. Use the SSH Command: In Git Bash, replace ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com with your instance’s Public IPv4 DNS (or IP address). The general SSH command looks like this:
   ssh -i "my-key-pair.pem" ec2-user@ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com

Or you can use the public IP:

   ssh -i "my-key-pair.pem" ec2-user@
  1. Accept the Security Warning:
    The first time you connect, you may see a warning about the authenticity of the host. Type yes to accept and proceed.

  2. Login:
    If everything is set up correctly, you’ll be connected to your EC2 instance and be presented with a terminal prompt for the ec2-user account.

Image description

  1. Cleanup or delete the instance:

Image description