Create EC2 instance and connect it via SSH Using Key Pair.

DevFunOps With Pradeep
4 min readMar 17, 2024

--

“In this thrilling article, we’re diving headfirst into the adventure of creating an EC2 instance and forging a secure SSH connection using a key pair.”

Let’s kick off our adventure by creating an EC2 instance!

To begin, head over to the AWS Management Console and simply search for “EC2” to access the EC2 service.

Please follow the steps outlined in the screenshot to create the EC2 Instance.

You’ll be redirected to the EC2 Dashboard, where you need to click on the “Launch Instance” button. That’s all there is to it!

Next, a new page will open where you’ll need to enter a few details. Follow the instructions exactly as shown in the image below.

Go ahead and refer below screenshot and start creating it as it is, below are the few steps which I would like to point out.

  1. Enter the Name.
  2. Select the Amazon Linux OS Image.
  3. Select the instance type as t2.micro free tier.

4. Key Pair — We can select the Existing Key Pair name or we can create a key pair securely SSH into your instance

Let’s create a new key pair by clicking on ‘Create new key pair.’
A new modal will open where you’ll need to enter a few details.

Follow the instructions exactly as shown in the image below.

5. Enter the key pair name in the designated field.

6. Select RSA as the key pair type.

7. Select the private key file format as .pem

8. Click on ‘Create key pair.’ A new key will be generated and automatically downloaded to your device.

In the screenshot above, in the ‘Key pair name’ dropdown, you will be able to see the key pair name that you just created.

9. Select the key pair that you created and proceed with the next steps.

10. Now, edit the network settings and enable ‘Auto assign public IP’, This action will enable the automatic assignment of a public IPv4 address to your EC2 instance, facilitating SSH access using this public IP.

11. Make sure to select the ‘Create security group’ option and keep the ‘Allow SSH Traffic’ checkbox selected. Choose the ‘Anywhere’ option from the dropdown menu next to it.

We keep the ‘Allow SSH Traffic’ checkbox selected to grant SSH access to our EC2 instance using the key that is already present on your device.

12. Now, proceed by clicking on the ‘Launch instance’ button. Your EC2 instance will then be created.

“Now, under the ‘Instances’ option, you will be able to see the instance that you have just created.”

Copy the Public IPv4 address of the instance.

Now that we have the key pair file downloaded on our machine, let’s proceed to SSH from your machine to the EC2 instance.

Now, execute the following command in your terminal (make sure you are specifying the correct path to the ‘.pem’ file):

chmod 400 path-to-your-.pem-file.pem

Now, use the following command to SSH into the EC2 instance:

ssh -i angulardeploymntKP.pem ec2-user@your-ipv4-address

Once you execute the above command in your terminal, it will prompt you with a message asking ‘Are you sure you want to continue?’ Simply type ‘yes’ and hit enter.

Congratulations! 🎉 You have successfully established a connection to the EC2 instance, opening up a world of possibilities for further configuration and deployment.

Fantastic! You’re now officially connected to your EC2 instance, ready to embark on your cloud adventure! 🎉🚀

If you encounter any issues or need further assistance, feel free to ask for help. Your feedback and questions are always welcome in the comments section below. We’re here to support you on your AWS journey!🚀🚀

As we draw our journey through AWS to a close, remember that the power to innovate lies within your grasp. With this dynamic tool at your disposal, the possibilities are boundless. Whether you’re advancing on a solo project or collaborating with a team, embrace the opportunities that AWS offers to revolutionize your development process. So, forge ahead, unleash your creativity, and let AWS propel you toward your next breakthrough. Until next time, happy coding! 🚀🚀

--

--