use*_*689 1 linux amazon amazon-ec2
我正在尝试使用具有自定义用户/密码的amazon linux distro创建ami图像。我所做的(手动):
ec2-useradminadminadmin到车轮组:usermod -aG wheel adminadmin到sudoers文件:sudo echo "admin ALL=NOPASSWD:ALL " > /etc/sudoers.d/admin/etc/sshd/sshd_config (PermitRootLogin yes
)/etc/init.d/ssh restartadmin-成功。但是,当创建新的ami图像并从新创建的ami午餐新实例时,通过用户admin或ec2-user- Permission denied
(publickey).
我错过了什么!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
Run Code Online (Sandbox Code Playgroud)
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.
| 归档时间: |
|
| 查看次数: |
2857 次 |
| 最近记录: |