Change key pair for AWS EC2 instance

  1. Stop the running EC2 instance.
  2. Detach its /dev/sda1 volume (let’s call it volume A)
  3. Start new t1.micro EC2 instance, using my new key pair
  4. Attach volume A to the new micro instance, as /dev/xvdf (or /dev/sdf)
  5. SSH to the new micro instance and mount volume A to /mnt/tmp
  6. Copy ~/.ssh/authorized_keys to /mnt/tmp/home/ubuntu/.ssh/authorized_keys
  7. Logout
  8. Terminate micro instance
  9. Detach volume A from it
  10. Attach volume A back to the main instance as /dev/sda1
  11. Start the main instance
  12. Login as before, using your new .pem file

Comments