Friday, 6 May 2022

How to Connect to an EC2 instance on AWS via SSH? | SpringBoot-Deploying to AWS EC2 Instance

🚀 Mastering the Cloud?

Join the Ram N Java community for high-quality AWS and Spring Boot tutorials!

SUBSCRIBE TO THE CHANNEL

Introduction

Connecting to an Amazon EC2 instance via SSH is a critical skill for any developer or DevOps engineer. Whether you're deploying a Spring Boot application or managing a server, SSH allows you to securely access your Linux machine from anywhere. In this guide, we'll walk through the entire process using an intermediate Linux machine and a .pem key file.

Step 1: Prepare Your Key File (.pem)

When you first launch an EC2 instance, AWS provides a .pem file (private key). You must have this file to authenticate your connection. If you are using a Linux machine to jump into another EC2 instance, follow these steps:

  • Open WinSCP or any file transfer tool.
  • Upload your .pem file to the Linux machine you are currently logged into.
  • Verify the file exists by running the ls command in your terminal.

Step 2: Secure Your Key File

SSH requires that your private key file is not publicly viewable. If the permissions are too open, the connection will be rejected. Run the following command to set the correct permissions:

chmod 400 your-key-file.pem

Step 3: Get Connection Details from AWS

To connect, you need the Public DNS or IP address of your instance:

  1. Go to the AWS EC2 Console.
  2. Select your running instance and click Connect.
  3. Under the SSH Client tab, copy the example command provided by AWS.

Step 4: Execute the SSH Command

Using the details from AWS, run the SSH command in your terminal. The structure looks like this:

ssh -i "your-key-file.pem" ec2-user@your-public-dns-name

Once you hit Enter, you'll be securely logged into your Amazon EC2 instance!

Conclusion

Congratulations! You've successfully connected to your AWS EC2 instance via SSH. This foundation allows you to install software, manage files, and deploy applications like Spring Boot with ease. Remember to keep your .pem files secure and never share them publicly!

2 comments:

Tutorials