How to change the EC2 public key?

I am trying to change my EC2 public key for myself, the rest of my team that uses AWS, and also to run instances.

So the old key was (for example) "my_key", and I created a new key called "my_key2".

I made a new key, saved the .pem file along with the old one, so both "my_key.pem" and "my_key2.pem" are in my ~ / .ssh folder.

Now I try to use ssh in other instances to change their authorization_keys to public key sharing, but when I try ssh, I get

amy$ ssh ***-**-**-***-***.foo.com Permission denied (publickey). 

I tried to extract the new file "my_key2" from the .ssh folder, and the same problem occurs. I did not have this problem before I started to cheat. Any tips on getting ssh to recognize my old certificates so that I can get everyone to switch to new keys?

+4
source share
2 answers

You will need to stop the instance (if the instance is EBS-enabled) in order to change the key pair that will be used for the instance. If you do not support the volume supported by EBS, you just need to start another instance from your AMI with a new key pair.

If you cannot easily reload the instance or create a new instance, there is a method that implies the possibility of changing the public keys in the running instance, but I did not try to try it. The really right way to do this is to stop / start or create new instances.

http://seabourneinc.com/2011/01/19/change-key-pairs-on-aws-ec2-instance/

+4
source

http://seabourneinc.com/2011/01/19/change-key-pairs-on-aws-ec2-instance/ This solution works. I checked it out. In simple steps. go into the AWS console, create a new pem key, it will ask you to save it on local, save it. run the following command.

ssh-keygen -y | tee my_key.pub enter the path to where you saved the new pem key file along with the file name.

the above command will display the content on the screen, copy it and paste into the authorized_keys of the EC2 instance file, save and close. Now you can use the saved / loaded new pem key file to access the EC2 instance.

0
source

All Articles