Is it possible to change the SSH Key on a running EC2 instance? If so, how?
Manage AWS more efficiently with RightScale: Try it free.
If you need to switch to a new SSH Key, RightScale recommends that you terminate the instance, change the associated SSH Key and launch the instance again. Before terminating the instance or taking any corrective action, make sure you've saved any critical data that needs to be preserved. So, if the instance has any attached EBS volumes, be sure to take snapshots of the volumes so that you can use them to restore your volume data on future instances. However, any data saved on the instance's local ephemeral drive will be lost once the instance is terminated.
If terminating and relaunching the instance is not feasible then the following instructions will allow you to change the authorized keys on the instance and update the Dashboard with the new key information.
#!/bin/bash -e echo "ssh-rsa $PUBLIC_SSH_KEY $KEY_NAME" > ~root/.ssh/authorized_keys exit 0 # Leave with a smile...
© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.