Skip to content

SSH-key/password Issues with a private Ubuntu 14 VMware image imported as AMI

0

Hello,

I apologize if this is splattered around this re:Post, not the easiest to navigate right away. Feel free to link me an old post with the same issue if that's proper.

  1. Exported running Ubuntu 14.04 from VMware as OVA
  2. Successfully uploaded to S3, and also successfully imported as an AMI
  3. If I boot from this AMI, I will always see the login, and it will ping. The OS loads without any issue.

Problem:

If I use a new ssh-key ( generate new from the console ), or use an older key, once it's booted up, these keys have no effect on establishing an SSH connection. It will prompt for password, and this is not due to permissions issue on the host key side just fyi. The old password on the system doesn't work with any combination of the legitimate old user, or if it was replaced ( not sure if it will do this ) with "ubuntu/root/ec2-user".

I tried SSHing from an older machine just in-case since the 14.04 is on openssh 6.6x but has no effect. Would someone possibly point me in the right direction to resolve this as quickly as possible? Or is the only solution to fix the original image pre-AMI, and do some specific adjustments?

Since it's running right now normally as an EC2 instance, but just not reachable via SSH, is there some other method to force the keys to work, or force a new password and ditch the keys? thanks

asked 2 years ago485 views

2 Answers
0

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.

EXPERT

answered 2 years ago

  • Hi Leo K, thanks for the quick comment. I should have clarified that last variable:

    1. the old system did not have ssh-keys in use, but pam un/pw authentication

    I should have thought to try that simple solution first, thanks brotha will give it a go.

0

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

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.