How to change EC2 Public Key?
amazon-ec2, amazon-web-services, pem, public-key, ssh
Solution
You will need to stop the instance (if EBS-backed instance) in order to change the key pair to be used for the instance. If not EBS-backed volume you will just need to start another instance from your AMI with the the new key pair.
If you are not able to easily restart the instance or create a new instance, there is this method which purports to being able to change public keys on a running instance, but I haven;t tried it. Really the right way to do it is by stopping/starting or creating new instances.
http://seabourneinc.com/2011/01/19/change-key-pairs-on-aws-ec2-instance/
Problem
I'm trying to change my EC2 public key for myself, the rest of my team who uses AWS, and also for running instances. So the old key was (for example) 'my_key', and I made a new key called 'my_key2'. I made the new key, saved the .pem file alongside the old one, so both 'my_key.pem' and 'my_key2.pem' are residing in my ~/.ssh folder. Now, I'm trying to ssh into other instances to change they authorization_keys to share my public key, but when I try to ssh, I get ``` amy$ ssh ***-**-**-***-***.foo.com Permission denied (publickey). ``` I tried taking the new 'my_key2' file out of the .ssh folder, and the same problem occurs. I didn't have this problem before I started mucking around. Any tips on getting ssh to recognize my old certificates so that I can get everyone going on the new keys?