Stop the running EC2 instance
Detach its /dev/sda1 volume (let's call it volume A)
Start new t1.micro EC2 instance, using my new key pair
Attach volume A to the new micro instance, as /dev/xvdf (or /dev/sdf)
SSH to the new micro instance and mount volume A to /mnt/tmp
Copy ~/.ssh/authorized_keys to /mnt/tmp/home/ubuntu/.ssh/authorized_keys
Logout
Terminate micro instance
Detach volume A from it
Attach volume A back to the main instance as /dev/sda1
Start the main instance
Login as before, using your new .pem file
AWS CentOS Root Keypairs
-
01-10-2022 - |
Question
I've launched a CentOS 6.4 AMI and configured it to act as a base instance for our application. I'm now trying to create an AMI from this which can be brought up as required.
Unfortunately when a new instance is created from the AMI the root user's key pair remains that which was assigned to the original template instance when it was created from a CentOS AMI. I was hoping that AWS would be able to assign a new key pair to each instance of the AMI as it's created. Although we won't be using the root key pair for day-to-day work on the instances, I'd prefer they didn't all share the same key.
Despite creating a new key pair at launch time I'm only able to log in using the original key. I've tried several solutions including removing the authorized_keys for the root user, but to no avail.
I'd appreciate any advice you can provide.
Thanks.
Solution 2
OTHER TIPS
I ran into this issue as well, with my Centos 6.5 image.
Here's how I fixed it:
Install the EPEL repo
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
Install the cloud-init package
yum install cloud-init
Add a user to the box called "cloud-user"
Add cloud-user to the sudoers file with the no password option
cloud-user ALL=(ALL) NOPASSWD: ALL
Stop the instance, and create the AMI.
When you launch an instance from that AMI you can choose any key you want, and when you login you will just use the following command
ssh -i yourkeyfile.pem cloud-user@your.ip.addy
To become root, just type the following
sudo -i
Cheers