Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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

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

Your Answer

 
discard

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.