Open In App

How To A Create A Key Pairs In AWS-EC2 ? |Complete Tutorial

In Amazon Web Services, an EC2 key pair consists of a public key and a private key that is used to securely communicate with EC2 instances. The public key is stored on the EC2 instance and is used to encrypt messages that can only be decrypted by the corresponding private key, which is kept by the user who generated the key pair. The private key is used to decrypt messages that have been encrypted with the public key.

What Is AWS EC2 Key Pair?

When launching an EC2 instance, you have the option to specify a key pair that will be used to encrypt login information and authenticate connections to the instance. If you do not specify a key pair when launching an instance, you will not be able to access it without additional steps, such as creating a new key pair or using an existing one.



We can create a Key Pair with two methods. They are

  1. When we are launching an EC2 Instance.
  2. We can also create a only Key Pair separately.

Types Of AWS EC2 Key Pairs

Following are the two types of key pairs available in the AWS they are



Step-by-Step Guide on Creating a Key Pair Using Amazon EC2

Step 1: Creating EC2 Instance

Step 2: Navigate To Key Pair Section

Step 3: Create A Key Pair

Step 4: Define Key Pair (.ppk Format )

Step 6: Review And Create Key Pair

Step 6: Downloading The Key Pair

Step 7: Verifying Created Key Pair

Launch EC2 Instance With Existing Key Pair : A Step-By-Step Guide

After launching the EC2 Instance, we are going to the EC2 Instance with Putty Method. So make sure that putty is available in your local system.

Step 1: Navigate To EC2

Step 2: Launch Instance

Step 3: Define The Instance

Step 4: Choose Existing Key Pair

Step 5: Review And Launch Instance

Step 6: Connect To Instance

Step 7: Open Putty In Setup

Step 8: Provide Credentials

Step 9: Connect To EC2 Instance

Step 10: Success Remote Login

How To Add A New Key Pair To An AWS EC2 Instance For SSH?

Here, we will guide you how to create and add new key pair to the existing AWS Instance. It helps in the case where you have an ec2-instance and you want to connect to instance with different users then you will need multiple ssh keys for enhancing security via connection.

Step 1: Configure SSH property rules

systemctl reload sshd
systemctl restart sshd

Step 2: Create Your Create Pair Locally

ssh-keygen -t rsa -b 2048 -f new_key_pair

chmod 400 new_key_pair
chmod 400 new_key_pair.pub

Step 2: Copy the Public Key To The EC2 Instance

cat >> authorized_keys

Step 3: Test The SSH Connection With New Key Pair

ssh -l root  -i new_key_pair.pem  instance_ip

Amazon EC2 Key Pairs And Amazon EC2 Instances

Amazon EC2 stands as Amazon Elastic Compute Cloud, It is a AWS Service that comes with offering effective and flexible computing service. It facilitates the users in launching the virtual servers commonly known as Instances within the AWS Infrastructure. Each created Virtual Machine (VM) is securely is securely accessed and managed through the key pairs. These key pairs are consists of public and private keys. The private key pair is provided to the user, which is very critical and should be keep it in secure. These public and private key files serves as primary method of authentication when connecting to EC2 instances remotely via SSH. Key pairs play a crucial role in ensuring the security and integrity of data and communications within the AWS Ecosystem facilitating the users with secured connection. It will act as a trusted choice for deploying the scalable and reliable cloud infrastructure solutions.

How Does AWS EC2 Key Pair Works?

A Key pair works through the principles of Asymmetric cryptography. It consists two mathematically related keys as private key and public key. The public key encrypts the data and corresponding private key used for decrypting that encrypted data. The point remember that When the data is encrypted with the public key it can only be decrypted by corresponding private key, other private can’t help in decrypting this. The public key is shared openly letting others to encrypt data and then it can only be decryptable by holder of private key. This method ensures in providing a secured communication with key pairs. Key pairs are fundamentals in securing digital communication such as secure server connections, data encryptions and digital signatures for authentication.

AWS CLI Command Of Creating A Key Pair

The AWS CLI mode of creating key pair provides the wide number of options for creating a key pair and flexibility over its connecting with instances. The following are the some of the popular options used while creating the AWS key pair.

Options Of Creating KeyPair

[ –key-name <value> ] : It specifies the name of the key pair. The value should be specified as unique name for the key pair.

[ –dry-run | –no-dry-run ] : It allows simulation of execution of command without actual creating the key pair.

[ -type <value> ] : It used for specifying the type of the key pair to generatesuch as the value be RSA, ECDSA etc.. depending on the type of supporting connection.

[ –key-format <value> ] : It used for specifying the format of the key pair and the value could be PEM, DER etc…

Example Of Create Key Pair With AWS CLI Option

The following example illustrates of creating a key pair with above specified options, here we are providing the key pair name as MyEC2KeyPair and running it without actual execution with providing the format of the key as PEM which stands for (Privacy Enhance Mail).

create-key-pair --key-name MyEC2KeyPair --no-dry-run -type RSA --key-format PEM

People Also Ask

How To Create AWS EC2 Instance

Read

How To Create S3 Bucket

Read

How To Install AWS CLI

Read

Conclusion

In Conclusion on using the concepts of asymmetric cryptography, AWS EC2 key pairs plays an essential role by guarantee a safe communication with EC2 instances. In this article we went on detailing what are EC2 key pairs and how to create them and they works behind. Whether you launching a new instances or configuring the settings it is essential for users in navigating the AWS environment for secured way of data operations.

AWS EC2 Key Pair – FAQs

What Is EC2 Key Pair?

EC2 Key Pair Is a set of cryptographic keys (public and private keys) that ued for securely connect to Amazon EC2 Instances. When you creating key pair public key is stored in the instance and private key file is downloaded to the local system. When you try to connect with, It goes for authentication.

Can I Add A Key Pair To An EC2 Instance?

Yes, You add a key to an ec2 instance while creating or configuring the instance settings for secure access.

Where Are EC2 Key Pairs Stored?

EC2 key pairs are stored locally on your computer that is used to connect to the instances. It is important to securely manage and store the private keys.

What Is The Difference Between EC2 Key Pair And Access Key?

An EC2 key pair is used for securely accessing EC2 instances with SSH protocol whereas Access keys are used for programmatic access of AWS services through APIs.

How Do Key Pairs Work?

Key Pairs work through asymmetric cryptography, Where the public key encrpts the data and the private key decrypts it for ensuring a secured communication and access control.

Can EC2 Have Multiple Key Pairs?

No, Each EC2 instance can only have one key pair association with them at a time. If you want you can replace the old existing one.


Article Tags :