How to Connect to an AWS EC2 Instance using SSH

Introduction

When you create an EC2 instance in AWS, it is like a computer running in the cloud. To use this computer, you need a way to log in and run commands.

For this, we use SSH (Secure Shell).
SSH allows us to connect safely from our local computer to the EC2 instance. Once connected, we can install software, run applications, and manage the server just like we do on our own laptop or PC.

Step 1: Select Your Instance and Click Connect

  • Go to AWS ConsoleEC2 Dashboard.

  • Select your running instance.

  • On the top, click the Connect button.


Step 2: Choose SSH Client and Copy the Command

  • A new window will open.

  • Click on the SSH Client tab.

  • You will see a command like this:

      ssh -i "your-key.pem" ubuntu@ec2-xx-xx-xx-xx.compute-1.amazonaws.com
    
  • Copy this command.


Step 3: Go to the Folder Where .pem File is Saved

  • Open CMD / PowerShell (Windows) or Terminal (Linux/Mac).

  • Go to the folder where you downloaded the .pem key file.
    Example:

      cd Downloads
    

Step 4: Paste the Command and Press Enter

  • Paste the command you copied from AWS.

  • Example:

      ssh -i "my-key.pem" ubuntu@ec2-3-95-123-45.compute-1.amazonaws.com
    

Step 5: Accept and Connect

  • First time, it will ask:

      Are you sure you want to continue connecting (yes/no)?
    
  • Type yes and press Enter.

Now you are inside your EC2 instance.

Another Related Article

If you want to connect your EC2 instance using PuTTY instead of SSH command, you can check this guide: How to Connect AWS EC2 Linux Instance Using PuTTY

0
Subscribe to my newsletter

Read articles from Shubhanshu Mohanty directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shubhanshu Mohanty
Shubhanshu Mohanty