Curtin Userdata customization: add "sudoer" user and set its password
The snippet can be accessed without any authentication.
Authored by
Fulvio Galeazzi
Edited
# Add an extra user, set password, add to sudoers
# Apparently, "ubuntu" user is not yet created, by the time late_commands runs
# Addendum: handling password hashes, based on:
# http://unix.stackexchange.com/questions/52108/how-to-create-sha512-password-hashes-on-command-line
#
# Get hash for password "paperino":
# python -c "import crypt, getpass, pwd; print crypt.crypt('paperino')"
# Check a given hash to verify it corresponds to some password:
# - select the hash portion up to the end of the 'salt', namely the
# piece of string comprised between $6$ and the next '$' character
# For example:
# python -c "import crypt, getpass, pwd; print crypt.crypt('paperino', '\$6\$Ck.Gim7WqVzsv8j9\$')"
diff -c curtin_userdata_ubuntu_amd64_generic_trusty curtin_userdata_ubuntu_amd64_generic_trusty_with-csduser
*** curtin_userdata_ubuntu_amd64_generic_trusty 2016-09-22 11:08:45.042776292 +0200
--- curtin_userdata_ubuntu_amd64_generic_trusty_with-csduser 2016-09-22 10:46:55.207425027 +0200
***************
*** 24,29 ****
--- 24,32 ----
driver_06_depmod: ["curtin", "in-target", "--", "depmod"]
driver_07_update_initramfs: ["curtin", "in-target", "--", "update-initramfs", "-u"]
{{endif}}
+ user_01_create: ["curtin", "in-target", "--", "sh", "-c", "/usr/sbin/useradd -m csdcloud"]
+ user_01_pass: ["curtin", "in-target", "--", "sh", "-c", "/bin/echo csdcloud:'$6$t8dFheE5qQM.7yVP$1r8rmUCtYOiBAvEcK7EZpIMtiLTgfC2FdBH04rF/Qy8YBfK1fEjbGxZhhpcR2KkDtGj7jbkbm/7eWtQOVER1R1' | /usr/sbin/chpasswd -e"]
+ user_01_sudo: ["curtin", "in-target", "--", "sh", "-c", "/bin/echo 'csdcloud ALL=(ALL:ALL) ALL' > /etc/sudoers.d/csdcloud"]
timezone_01_config: ["curtin", "in-target", "--", "sh", "-c", "ln -sf /usr/share/zoneinfo/Europe/Vatican /etc/timezone"]
timezone_02_set: ["curtin", "in-target", "--", "sh", "-c", "dpkg-reconfigure --frontend noninteractive tzdata"]
limits_01_add: ["curtin", "in-target", "--", "sh", "-c", "/bin/echo '* soft nofile 100000' >> /etc/security/limits.conf ; /bin/echo '* hard nofile 100000' >> /etc/security/limits.conf"]
Please register or sign in to comment