How to Change Authentication Key Pair in EC2 Instance(Linux Server)
in very easy and detailed Steps.
We currently have a running Linux server that has a Key pair enabled. In the subsequent steps, I will demonstrate the change authentication Key pair to server/instance and also how to generate a PPM key and convert it to a PPK key. If you already possess a PPK key, you may use it directly without the need for additional generation or conversion steps.
To whitelist your IP and allow access to your server’s Security Group options, please follow these steps:
a. Select the server that you wish to configure.
b. Navigate to the Security Group options and click on the Inbound rule.
c. Add your IP address to the whitelist and save the rule. In inbound rules use the Source column dropdown as “My IP” and write your Name in the Description.
d. To complete this process, go to the Security tab of your selected server and follow the above steps. This will ensure that your IP is allowed access to the server’s inbound rule.
To access the server, please utilize Putty or Mobaxterm for logging in, and take note of the Public IP address of the server. In the event that you possess a private server, kindly log in through the Bastion host and ensure to whitelist your IP in the Bastion Host, if necessary. Please note that for demonstration purposes, we will be using a public server.
Search on your Computer and open Putty if you have already downloaded Putty.
Paste or Write the IP address of the server in HostName or (IP address).
On the left side, the panel Clicks on SSH then Auth, and then Credentials.
In the right-side panel click on Browse and load/choose the PPK you have generated. Click Open.
Login as ec2-user or ubuntu or root. In my case ec2-user.
Write these commands :
1. sudo su -
2. cd /home/ec2-user/.ssh
Take the backup of the Authentication Key File.
3. cp authorized_keys authorized_keys.bkp
4. cat authorized_keys
Note: Please note that it is important to keep the Terminal window open. In case the Terminal becomes inactive, you can easily restart it by simply right-clicking on the Terminal window.
Go to the left side and click on the Key Pairs and create a new Key pair.
Click on Create Key Pair and create a New Key Pair.
Name your New Key Pair and I have chosen the .pem key file format. Give a Tag so it can easy to find out. Click on Create KeyPair.
Go to “Puttygen”, Load the New Private Key File (Pem), and then click ok.
To ensure a successful login to your EC2 server after changing the authentication Key, please follow these steps carefully. Firstly, refer to the image provided and copy the text before “imported-openssh-key” from the first line as shown in the image below. Next, paste this text onto Notepad, as it will be required for the following steps. It is crucial that you avoid making any errors while copying, as this may prevent you from logging into your EC2 server. If you have any questions or concerns, please do not hesitate to ask for assistance.
Note: While copying doesn’t copy the space of last or initial.
Using the Save private key button Save the private key file in .ppk Format.
Go to the Terminal again in the 4th step: vi authorized_keys.
Enter “ i ” to insert and remove previous authentication lines and paste the newly copied authentication Lines.
After the above, Click the Esc button and then write “ :wq! ” to save the changes and exit the file. Check the shown below Image.
Use the below command to verify.
cat authorized_keys
Without Closing, Right Click on the terminal and create New Session (Necessary Step), and Login with the same Public Ip but with New Key.
“This following step is to use only check the New authentication Key is working,while preserving/affecting the integrity of any existing Terminal sessions.”
After Login through Putty to the server through New Key, in my case, my key pair name is “Temporary_New_Key_Pair”, we are able to log in.
You can check and log in through the old Key pair you are also not able to Log in.
Suggestions, improvements, and queries are welcome.
I hope this blog helps and saves your precious time so that you can spend it with your loved ones. Keep Smiling and show some love !!! Thank you for reading, if you enjoyed it, please hit the clap button and share it also.
Below are the Links to a series of Detailed | Step by Step of WordPress Website Hosting on AWS Lightsail :
Part 1: How to host a WordPress website on AWS LightSail.
Part 2: Find Login Credentials of the Dashboard of WordPress AWS Lighstail.
Part 3: Setting up a Lightsail Static IP Address from Dynamic IP Address.
Part 3.1: Dynamic IP address of Instances in AWS Lightsail.
Part 4: How to Register a Domain Name with Amazon Web Service | Register a Domain Name using AWS Route53.
Part 4.1: Connect a Route53 Registered Domain to AWS Lightsail Instance. (Above Article)
Part 5: Set up a Free SSL Certificate on WordPress AWS Lightsail.
Other Blogs:
If you like the above Blog on Cloud Computing Please Support Me through “Buymeacoffee ”.
Follow us for more content.
More content at Nerd For Tech.