Different Ways to change .Pem file of AWS instance Part : - 1 (Using Session manager)

Key

  • Pem file is a private key file that you download when you first time generate key from key pair section or when you create an instance. It is use to securely connect your instance using terminal. So AWS stores public key and they let us download .Pem one time only.

  • In that case, Someone may loose .Pem file by mistake and you are not able to ssh in your instance without .Pem file. So the question is  How to change your .Pem file of your instance in this scenario. 

  • There are  3 ways that i know, how to change .Pem file. 
    1. Using Session Manager
    2. Using AWS-Support Reset Access automation document in System Manager
    3. Using new instance
  • I will guide you through the step wise. In this blog i will explain how to change .Pem file using Session Manager. This use full when your instance is running or it is instance store backed, so in that case this is very useful method. If you haven't attach the System Manager role to AWS instance then this can be done using how to connect AWS instance when you lost .Pem file. 

  • After completing above step open terminal through session manager and follow below steps.


Step : - 1   Change user to root and then change it to Ubuntu user. Now create new instance or If you have instance with different key and you want to use that key then no need to create new one.

 
Step : - 2   You need to ssh into different instance / new instance which .Pem file is available in you System. Go to .ssh directory and copy the content of authorized_key file (command : cat  ~/.ssh/authorized_key ) means public key of related to .Pem file name.


Step : - 3   After paste this public key to your old instance's (instance with lost .Pem file ) authorized_keys file ( access using session manager ) , save and close authorized_keys file .


Step : - 4   Now you can ssh into instance with different .Pem file. This is easiest way to change .Pem without losing any kind of data. You can do it even with your running instance.

Comments

Popular posts from this blog

Different Ways to change .Pem file of AWS instance Part : - 2 ( Using Reset-Access Document )

Contact Me

Name

Email *

Message *