- Newest
- Most votes
- Most comments
I haven't used the VM import feature for a few years, but according to documentation, it shouldn't change the configuration of users present on the system, and it doesn't create the ec2-user (or "ubuntu" in the case of AWS's standard Ubuntu AMIs): https://docs.aws.amazon.com/vm-import/latest/userguide/prepare-vm-image.html#prepare-vm-image-linux
To be sure, you are able to log on to the system with a public key at the source, but the exact same key supplied to the exact same user as before is no longer accepted after launching the image as an EC2 instance?
If you want a quick workaround instead of troubleshooting the import tool, you could launch a brand new, temporary instance in the same AZ from a standard AWS AMI, detach the root volume from the imported instance, attach it to the temporary instance, and inspect and correct the credentials configuration there. Then just reattach the volume to the original instance and boot it up.
Steps I do for my own AMI's are this.
When running your VM, as root, create a user, remove the password and add it to the sudo group:
useradd -s /bin/bash -m yourusername
passwd -d yourusername
usermod -aG sudo yourusername
switch to the user, create ssh-key (you can accept the defaults) and rename the public key to authorized_keys.
ssh-keygen
mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
Copy your private key to a text file on your computer and remove from the server.
cat ~/.ssh/id_rsa
rm ~/.ssh/id_rsa
Be sure to change the permissions of folder .ssh and .ssh/authorized_keys
chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys
Now export your VM and create your AMI. You should be able to login with "yourusername@ip-address -i id_rsa"
answered 2 years ago
Relevant content
asked 4 years ago
asked 5 years ago

Hi Leo K, thanks for the quick comment. I should have clarified that last variable:
I should have thought to try that simple solution first, thanks brotha will give it a go.