Im trying to create an ami image using amazon linux distro with a custom user/pass. What I did (manaualy):
ec2-user
admin
admin
admin
to wheel group: usermod -aG wheel admin
admin
to sudoers file: sudo echo "admin ALL=NOPASSWD:ALL " > /etc/sudoers.d/admin
/etc/sshd/sshd_config
(PermitRootLogin yes
)
/etc/init.d/ssh restart
admin
- success. But when creating a
new ami image and lunch new instance from the newly created ami,
loging via user admin
or ec2-user
- Permission denied
(publickey).
What am I missing!!The issue is that the EC2 service is not aware of your changes when you are launching the instance with the AMI you created. I found a solution for that problem using Cloud-Init which is built-in on Amazon Linux and other official AMIs as well, the complete tutorial can be found here: https://emagalha.es/blog/2018/01/21/customizing-the-default-user-of-an-ubuntu-ami/
In short, here is what you need to do:
#cloud-config
system_info:
default_user:
name: admin
Connect to the instance using the admin user and create a file at /etc/cloud/cloud.cfg.d/defaults.cfg
with the same contents of the user data file you used to launch the instance.
Shut down the instance and create the AMI
Enjoy!
You can also update the /etc/cloud/cloud.cfg.d/00_defaults.cfg
inside the instance with the new username instead of creating a new file. I just like creating a new file to make the change more transparent, in any case, the choice is yours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With