Is it possible to change the SSH Key on a running EC2 instance? If so, how?
For various security reasons it can be a good idea to change ssh keys. Amazon doesn’t actually let you change keys for a live instance. If you can easily restart your instance, that’s the best way to change the key pair. However, sometimes restarting an instance can be a much larger hassle than manually changing the keys. We recently ran into this very situation, so here’s a workaround:
Generate a new key pair
Login to your AWS management console. Go the ec2 tab, then select “key pairs” from the sidebar. Now all you have to do is click “Create key pair.” AWS will give you the private key and store the public key. Copy the private key into a file on your local computer. We’ll call it my_key.pem for this walkthrough.
#sudo nano /etc/ssh/sshd_config
#sudo /etc/init.d/ssh restart
What do you think?