Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an EC2 instance which I started with a particular key pair. But now I want to disable the key pair that I have and use a different one. I just created a new keypair, but how do I assign it to the instance without having to terminate the instance and restart it?

share|improve this question
Is that Linux or Windows instance? – Dusan Bajic Jun 11 '12 at 9:06

Altering the related authorized keys file will be sufficient. You don't even have to restart the sshd daemon.

The ssh-keygen program will allow you to create a new key and will ask you what name to save the key under. Enter any name you choose. Copy the file with that name to your system as your private key. Copy the contents of file with the same name ending in .pub to your authorized_keys file. Remove any lines from that file that you don't want to be used anymore.

Think twice, operate once. Locking yourself out will require at least a reboot to fix.

share|improve this answer

You should copy the public key file onto the instance and add it to (or replace) the existing authorized_keys file. Or, better yet, have your configuration automation system do it for you.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.