Skip to main content

How to Use SSH with AWS EC2 Instance?

In this article, we will discuss "How to Use SSH with AWS EC2 Instance?". As I already explain the setup of EC2 Instance and the use of an Elastic IP in my previous article. Today, we will learn how to connect an EC2 instance using SSH. If still, you have not read my previous articles then I recommend checking them once for a better understanding.

Prerequisites



  • A running EC2 Instance.

  • Elastic IP (Optional for this article)

  • ".pem" file, which is downloaded when setup the EC2 Instance. If not having the ".pem" file, then you have to create new key/value pairs.


Connect via Terminal or WSL(Window Subsystem for Linux)


Open your terminal and go to the directory where you downloaded your ".pem" file. Use the following command to connect with the server.
ssh -i "****.pem" username@<publicDNS> or <IP Address>



The same terminal command can be used in the windows Linux terminal. I'm using ubuntu on my windows machine. You can check the given screenshot.


SSH Command Explanation



  • ssh: Command to use SSH protocol

  • -i: Flag that specifies an alternate identification file to use for public-key authentication.

  • username: Username that uses your instance

  • IP-address: IP address is given to your instance

  • public DNS: Public DNS of the EC2 Instance


Connect via Putty (Windows only)


Need to install putty on your Windows machine. Then open "PuttyGen" (it is included with your Putty Client installation) on your PC.



Make sure the checkbox "RSA" is selected. After that click the load button and go to the folder where you have stored your ".pem" file, select it and choose open.



A popup appears when successfully loading the ".pem" file. Click on the save private key button. Then a message will prompt, click on the yes.



Now save the ".ppk" key with a unique name. After that close the PuttyGen program and open Putty. Go to the SSH section and expand the section. Now select the Auth section and select the ".ppk" file that we just created.



Go back to the top of the menu and selects the Session section. Fill the field Hostname (Host/IP address) with the IP address given to your AWS EC2 instance and click open.



A warning message will prompt. The server host is not registered on our PC, so we must add it. Click yes.



A window will prompt asking for the username, type your username for ssh access, by default its ubuntu.



Now we are connected to our AWS instance using Putty.

Conclusion


In this article, we are discussing "How to Use SSH with AWS EC2 Instance?". As you see, the steps are simple and easy. Hope you like this article, please feel free to add comments if any queries or also send me your feedback.

Keep learning and stay safe ;)




You may like:

Basic Understanding on AWS Lambda

How to Manage AWS Lambda Versioning and Aliases

Laravel Sanctum – Restful API Authentication

Comments

Popular posts from this blog

Basic Use of Model Factories in Laravel

In this article, we will discuss the basic use of Model Factories in Laravel. Laravel comes with the feature called model factories that are offered to made fake models quickly. It’s used in the database testing and database seeding. Let’s start the discussion on this feature by... Read out the full post at here

How to Manage Elastic IP in AWS?

In this article, we will discuss "How to Manage Elastic IP in AWS?" . Here, you will learn the use of Elastic IP addresses and how to assign it to your EC2 Instance. If you are new with EC2 Instance then check out my previous article, "How to setup an EC2 Instance on AWS" . EC2 (Amazon Elastic Compute Cloud) provide us an ability to create, start, stop and terminate the instance at any time. This will creates a challenge with IP addresses, because restarting an instance or replacing a terminated instance with newly created instance, will result in a new IP address. Now the question is "How to reference a machine when the IP is constantly change?" . We can handle this situation with the use of Elastic IP address. We can associate a single Elastic IP address to different Ec2 Instances. You can immediately associate a new Ec2 Instance with the Elastic IP address if the EC2 instance is stopped or terminated. After the back-end EC2 instance changes, our exist...

How to use trackBy in Angular with Example

In this article, we will discuss "How to use trackBy in Angular" . Basically, " trackBy " is used to improve the performance of an angular application. Today, I will try to explain the use of trackBy with an example. Why do we need trackBy in Angular? By default, no need to use trackBy in Angular. But with large collections of data, angular ngFor directive may perform poorly. For example, a small change of data such as adding a new record, editing, or deleting a record from the collection. The angular framework will remove all the DOM elements that are associated with the data and will create them again in the DOM tree even if the same data is coming. Here, a lot of DOM manipulation will happen in the background if a large amount of data comes from the API then the application performance will suffer. Angular trackBy example Angular provides us function trackBy which helps us to track the items which have been added or deleted. The trackBy function takes two argum...