SmartOS - custom LX zone template
I want all of my Ubuntu "machines" to be ready to be managed by Ansible. In my case that requires adding a user and the ssh key.
Here is a quick and dirty script I wrote to prepare the "machine". Once I have the container ready, I make an image from it and use that the base for the rest of my "machines". I also tweaked the timezone. This works for RockyLinux as well, except the group is wheel
not sudo
.
#!/bin/bash
useradd -s /bin/bash -G sudo -m -c "Ansible user" your-user-here
echo "your-user-here ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/91-ansible-usr
mkdir /home/your-user-here/.ssh/
echo "ssh-ed25519 qoGMBcDyDHmgThs/kPIyAXsX0lTAiq" > /home/your-user-here/.ssh/authorized_keys
chown -R your-user-here:your-user-here /home/your-user-here
chmod 700 /home/your-user-here/.ssh
chmod 400 /home/your-user-here/.ssh/authorized_keys
rm /etc/ssh/ssh_host_*
truncate -s 0 /etc/machine-id
rm /etc/localtime
ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
This way I have a consistent base image for all machines in my data center.