How to Connect an EC2 Instance to an External Sources (Terminals)

Connecting an Amazon EC2 instance to external sources using SSH clients like PuTTY & MobaXterm is a fundamental skill for managing remote cloud resources. Here’s a step-by-step guide on how to set up and connect to your EC2 instance using PuTTY & MobaXterm .

Prerequisites

  1. AWS Account – You need an AWS account with an EC2 instance already created and running you can this links for creating and launch an EC2 Instance

    • Creation of AWS Account - Refer this for creation of AWS Account : Link

    • Launch an EC2 Instance - Refer this for Launching an EC2 Instance : Link

  2. Key Pair File (.pem) – During the EC2 instance setup, AWS provides a key pair file (.pem). You’ll need this to connect to your instance.

Step-by-Step Guide

Step 1: Configure Security Groups

To ensure that your EC2 instance is accessible, the security group associated with it must allow incoming connections on port 22 (SSH). Here’s how to check and update the security group

  1. Go to the EC2 Dashboard in the AWS Management Console.

  2. Select Instances, and click on your instance to see its details.

  3. Under Security, find the Security Groups section, and click on the linked security group.

  4. In the security group details, select Edit inbound rules.

  5. Add an Inbound rule for SSH with:

    • Type: SSH

    • Protocol: TCP

    • Port Range: 22

    • Source: Select either a specific IP (for increased security) or “Anywhere” (0.0.0.0/0) if you want open access.

Step 2: Installing PuTTY Software

  1. We first need to install PuTTY

Step 3: Convert PEM to PPK Format

  1. EC2 instances use a .pem key file for SSH access, but PuTTY requires the key to be in .ppk format. Here's how to convert your key file

  2. Launch PuTTYgen Application on your system. PuTTYgen Application will automatically downloads with PuTTY Application.

  3. Load Your PEM File

    • Click on the “Load” button.

    • Change the file type to display “All Files (.)” and select your .pem file.

    • Keeping the Key passphase is optional.

  4. Save the Private Key:

Step 4: Connect to EC2 Using PuTTY

  1. Open PuTTY.

  2. In the Host Name (or IP address) field, enter the Public DNS or Public IP of your EC2 instance. You can find this information in the EC2 Dashboard under Instance Details.

  3. In the Category menu on the left, go to Connection > SSH > Auth.

  4. Under the Auth section, go to the Credentials tab, then click Browse next to "Private key file for authentication" to locate and select your .ppk file.

  1. Click Open to start the connection.

Step 5: Log into the EC2 Instance

  1. Once PuTTY connects to the instance, a terminal window will open. If you’re prompted with a security alert, accept it to proceed.

  2. It will ask for login as "login as": it should be default user of an EC2 Instance

  3. Passphrase for key "imported-openssh-key": One should provide key passphase provided during the step 3. while converting the .pem file to .ppk file.

  4. For Reference: the default usernames for popular AMIs

    • Amazon Linux: ec2-user

    • Ubuntu: ubuntu

    • RHEL: ec2-user

    • SUSE: ec2-user

  5. If the login is successful, you’re now connected to your EC2 instance using PuTTY!

Connecting an EC2 instance using PuTTY is a secure and effective way to manage your cloud resources remotely. This setup lets you work with and control your instance as if it were a local server, providing full administrative access.

Happy cloud computing!