====== Prepare template ====== Run this script before cloning a template ''preclone-deb.sh'' optimized for ubuntu 18.04 #!/bin/bash # apt apt --yes --purge autoremove apt clean # cleanup /var/log /usr/sbin/logrotate –f /etc/logrotate.conf find /var/log/ -name "*.gz" -exec rm {} \; find /var/log/ -name "*.1" -exec rm {} \; /bin/cat /dev/null > /var/log/wtmp journalctl --vacuum-size=10M # clean tmp /bin/rm –rf /tmp/* /bin/rm –rf /var/tmp/* # clean root history /bin/rm -f ~root/.bash_history unset HISTFILE # remote SSH keys systemctl stop ssh.service rm -f /etc/ssh/*key* # clean up personal stuff rm -rf /root/.ssh rm -f /root/.bash_history # clean out udev persistance rm -f /etc/udev/rules.d/70-persistent-*.rules # backup rc.local before modification #mv -f /etc/rc.local{,.preclone} cat > /etc/rc.local << EOF #!/bin/bash # # post-clone script (cleans up, re-initializes and such after clone) # # the sshd keys have been remove by the pre-clone script - generate new ones /usr/sbin/dpkg-reconfigure openssh-server systemctl restart ssh.service # restore original rc.local (keep at the bottom) #/bin/mv -f /etc/rc.local{.preclone,} /bin/rm -f /etc/rc.local exit 0 EOF # make the new script executable chmod 755 /etc/rc.local # Discard unused space fstrim -a # power off the system shutdown -h now