From 33d30a2ffec25cc5287e49f4d300b210ec3deeaa Mon Sep 17 00:00:00 2001 From: Mischa Taylor Date: Mon, 24 Jun 2024 22:30:53 +0000 Subject: [PATCH] Add script to clear out machine information --- .../scripts/clear-machine-information.sh | 24 +++++++++++++++++++ ubuntu/cloud/x86_64/README.md | 4 ++-- ubuntu/cloud/x86_64/ubuntu.pkr.hcl | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 ubuntu/cloud/scripts/clear-machine-information.sh diff --git a/ubuntu/cloud/scripts/clear-machine-information.sh b/ubuntu/cloud/scripts/clear-machine-information.sh new file mode 100644 index 0000000..8736903 --- /dev/null +++ b/ubuntu/cloud/scripts/clear-machine-information.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +echo "==> Autoremove packages and clear the package cache" +apt-get --assume-yes autoremove +apt-get --assume-yes clean + +echo "==> Reset machine ID" +truncate -s 0 /etc/machine-id +[ -f /var/lib/dbus/machine-id ] && truncate -s 0 /var/lib/dbus/machine-id + +echo "==> Remove SSH host keys (will be regenerated on first boot)" +rm --force /etc/ssh/ssh_host_* + +echo "==> Remove the random seed file (will be regenerated on first boot)" +systemctl --quiet is-active systemd-random-seed.service && systemctl stop systemd-random-seed.service +[ -f /var/lib/systemd/random-seed ] && rm --force /var/lib/systemd/random-seed + +echo "==> Clear log files" +find /var/log -type f -delete + +echo "==> Clear the bash history" +export HISTSIZE=0 +truncate -s 0 ~/.bash_history +unset HISTFILE diff --git a/ubuntu/cloud/x86_64/README.md b/ubuntu/cloud/x86_64/README.md index 624b406..dc6ff40 100644 --- a/ubuntu/cloud/x86_64/README.md +++ b/ubuntu/cloud/x86_64/README.md @@ -266,8 +266,8 @@ enp1s0 UP 192.168.107.79/24 fda2:8d37:bed8:93ee:5054:ff:fe ``` ``` -$ virsh shutdown ubuntu-server-2004 -$ virsh undefine ubuntu-server-2004 --nvram --remove-all-storage +$ virsh shutdown ubuntu-server-2204 +$ virsh undefine ubuntu-server-2204 --nvram --remove-all-storage ``` ## Ubuntu 22.04 BIOS virtual firmware diff --git a/ubuntu/cloud/x86_64/ubuntu.pkr.hcl b/ubuntu/cloud/x86_64/ubuntu.pkr.hcl index e963d68..18128b7 100644 --- a/ubuntu/cloud/x86_64/ubuntu.pkr.hcl +++ b/ubuntu/cloud/x86_64/ubuntu.pkr.hcl @@ -112,6 +112,7 @@ build { scripts = [ "../scripts/disable-updates.sh", "../scripts/qemu.sh", + "../scripts/clear-machine-information.sh" ] } }