What must you clean up before capturing an image?
AdvancedProductionPatching, Automation & Golden Images
Answer
sudo cloud-init clean --logs --machine-id # reset cloud-init state and machine-id
sudo truncate -s0 /etc/machine-id
sudo rm -f /etc/ssh/ssh_host_* # regenerated on first boot
sudo rm -rf /tmp/* /var/tmp/* /root/.ssh/authorized_keys /home/*/.bash_history
sudo journalctl --rotate && sudo journalctl --vacuum-time=1s
Duplicate machine-ids break DHCP client IDs, journald and some monitoring agents; duplicate SSH host keys make every server look identical to an attacker.
More on Patching, Automation & Golden Images
What does a good Linux patching strategy look like?BeginnerIn-place patching vs immutable image replacement: which do you prefer?IntermediateHow do you know whether a server needs a reboot after patching?BeginnerHow do you configure automatic security updates?BeginnerWhat is kernel live patching?IntermediateHow do you roll kernel updates across a 200-node fleet safely?Advanced