skip to Main Content

I’m working on a project where I’ve created a custom environment that includes custom applications using the NVIDIA driver, CUDA, etc. Users need to sign in to this environment using RDP (xrdp) on an EC2 instance. I have this working on an instance based on the "Deep Learning Base OSS Nvidia Driver GPU AMI (Ubuntu 22.04)". My goal is to create a custom AMI from this instance so that users can easily start a new instance, log in via RDP, and use the environment.

In the base AMI, the "ubuntu" user doesn’t have a password set. Currently, I can set the password manually by connecting to the instance via SSH and using sudo passwd ubuntu, but I’d like to avoid this step for end users who might not have SSH clients available. After creating the custom AMI and launching a new instance from it, the "ubuntu" user password I set on the original instance doesn’t carry over to the new instances.

How can I set a default password for the "ubuntu" user in my custom AMI so that it persists across new instances? Any help or suggestions would be greatly appreciated. Thanks!

2

Answers


  1. Chosen as BEST ANSWER

    For anyone facing the same problem, following is the solution that worked for me: taken from here

    When launching an instance from an image, AWS will disbale the root and main account for password authentication.

    in case ubuntu [user : root,ubuntu] in case ami : [user : ec2-user] It means , these account can not login through password authentication on a fresh launched ec2.

    However, any other account, will be working. so let's suppose, you create an instance from ubuntu, set password authentication yes in ssh and setup password for ubuntu, along with this, you created another user for your self, then ,you launch one instance from the image of above configured ec2.

    then password authentication for ubuntu user will not work , hwoever, password authentication for another user will work.


  2. If your use case is just to let users to connect to the EC2 instance you can ditribute a key pair that users will use when they create the EC2.

    But if your needs is a password authentication for some reasons you can use AWS Image builder to:

    • Create a new image pipeline with the specified image
    • Create a new recipe with base image and the components (scripts or configuration changes) you want to apply.
    • Add a component with Linux as a platform and add a shell script to the install section.

    script to add

    #!/bin/bash
    echo 'ubuntu:<your-password>' | chpasswd
    echo 'disable_root: true' >> /etc/cloud/cloud.cfg
    echo 'ssh_pwauth: true' >> /etc/cloud/cloud.cfg
    echo 'chpasswd:' >> /etc/cloud/cloud.cfg
    echo '  expire: false' >> /etc/cloud/cloud.cfg
    
    • In the Image Recipe, add the component you just created.
    • run ths image pipeline
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search