I have seen several questions and answers about changing the EC2 key pair for a running instance. However I am a complete AWS newbie at this point and I can easily stop the
You can create an AMI of your current instance and spin up a new instance with a different key pair using that AMI. You can then associate your elastic IP with the new instance. Is that what you're looking to do?
No, you can't change the key pair for an instance using AWS management console. The only way to change the key is explained here: Change key pair for ec2 instance
In a nutshell, SSH key is a file, created in the EC2 instance by AWS during setup. Once the file is there, AWS is not touching it. It's only you who can work with it.
I agree with @yegor256 on the best method here to change your keys. You can also visually inspect the authorized_keys file to ensure that only the correct keys are listed--especially when using someone else's AMI. Just be sure the file has the correct permissions or you could lock yourself out accidentally.
You are sort of out of luck with regards to changing the key pair associated with the instance. What you can do, though, is one of the following:
For future reference, best practice would be to have a common key file that is not accessible to everyone to create EC2 instances, then assign credentials for people to do work on them.
Change key pair in AWS Ec2 instance.
Sometimes it's necessary to change the private key for some security reason. We can able to change the private key or key pair while running the Ec2 instances.
In the case of changing the private key pair, we need to enter the SSH using the below command.
• Chmod 400 key.pem • Ssh user @ip-ikey.pem
Example: ssh ubuntu@108.23.68.92-itest.pam
Change the existing key pair
ssh-keygen
The created private key will be restored in /home/user/.ssh/id_rsa
, and the public key will be stored in /home/user/.ssh/id_rsa.pub
.
Then copy the public key from id_rsa.pub file to /home/user/.ssh/authorized_ key file
.
The next step is to copy the private key which named as “id_rsa” in the file and then recreate the new file name it as (try. pem) in the local system.
Connect to Ec2 instance by using the recently created private key.
chmod 400 try.pem
ssh Ubuntu@ip –I try.pem
Start your instance by using the private key. enter link description here