Connecting to Amazon EC2 Instances Using SSH

Kelvin ParmarKelvin Parmar
3 min read

Introduction

Amazon Web Services (AWS) has become a cornerstone in the world of cloud computing, providing scalable and reliable infrastructure for businesses and individuals alike. Amazon EC2 (Elastic Compute Cloud) is a popular cloud computing service that allows users to run virtual servers in the cloud. One of the common ways to connect to an EC2 instance securely is through SSH (Secure Shell). In this guide, we'll walk you through the steps to connect to an EC2 instance using the built-in SSH client, without the need for any third-party software.

Step 1: Launching an EC2 Instance

Before you can connect to an EC2 instance, you need to launch one. This involves selecting the appropriate Amazon Machine Image (AMI), configuring instance details, adding storage, and setting up security groups. We already created in our last blog you can also that blog here: https://kelvin-parmar.hashnode.dev/aws-ec2-empowering-your-cloud-journey-with-virtual-servers

After creating a EC2 instance click on Connect button where you can find all the details to connect in you local machine using SSH.

Step 2: Generating SSH Key Pair

Security is paramount when it comes to managing AWS resources. To secure the communication between your local machine and the EC2 instance, SSH key pairs are used. The guide emphasizes the importance of creating and managing SSH key pairs for a secure connection. It walks you through the process of generating an SSH key pair using the ssh-keygen command.

Step 3: Get Your Key Pair

When launching an EC2 instance, you specify a key pair. Ensure you have the private key file (.pem) associated with that key pair.

Open yout terminal where your .pem file is stored. Here in my case I downloaded into downloads folder so opened into my cmd.

After that run the below command. Replace "test-ec2.pem" with the actual path to your private key file.

chmod 400 "test-ec2.pem"

Step 4: Connect Using SSH

Use the ssh command to connect to your EC2 instance. Adjust the following command with your information:

ssh -i /path/to/your/keyfile.pem ec2-user@your-instance-ip

Replace /path/to/your/keyfile.pem with your private key file path and your-instance-ip with the EC2 instance's public IP address or DNS name. Note that the default username for Amazon Linux instances is usually ec2-user.

For example:

ssh -i "test-ec2.pem" ubuntu@ec2-13-126-13-170.ap-south-1.compute.amazonaws.com

Bonus Tip: Windows Users

If you're using Windows, you can utilize the built-in SSH client or a tool like PuTTY. However, this guide demonstrates that, even on Windows, you can opt for the command line without the need for additional software.

Conclusion

By following these simple steps, you can connect to your Amazon EC2 instance securely using SSH. Whether you're using a Mac, Linux, or even Windows with its built-in SSH client, this guide eliminates the need for third-party software, providing a streamlined and secure connection experience.

If you find it helpful then like it and subscribe to more articles on aws cloud journey.

Twitter LinkedIn Hashnode

1
Subscribe to my newsletter

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

Written by

Kelvin Parmar
Kelvin Parmar

I am B.tech Graduate who is Passionate about Tech and Open Source. Programmer with a good sense of design. Learning and sharing in Public and helping the tech communities. I write about my experiences, tech and tools. Educating and Helping people get into Tech and Open Source through my Content.