Skip to content

Instantly share code, notes, and snippets.

@mortn
Last active May 18, 2024 18:32
Show Gist options
  • Save mortn/a104d868857c063cf4d3 to your computer and use it in GitHub Desktop.
Save mortn/a104d868857c063cf4d3 to your computer and use it in GitHub Desktop.
VM Clean Up (cleaning up Debian based system for use as template)
#!/bin/bash
# Clean up Apt
apt-get autoremove
apt-get autoclean
apt-get clean
# Delete SaltStack minion keys and ID file
# New files are generated when the service starts
rm -vf /etc/salt/pki/minion/*
rm -vf /etc/salt/minion_id
# Generate new SSH host keys
for T in dsa rsa ecdsa; do
echo -e 'y\n'|ssh-keygen -t $T -N "" -f /etc/ssh/ssh_host_${T}_key
done
# Remove everything in the /tmp directory:
rm -rvf /tmp/*
# Clean up logs
rm -vf /var/log/wtmp /var/log/btmp
rm -vf /var/log/*.log.*
rm -vf /var/log/*/*
# Clean up the command history:
history -c
# Almost done but we don't want to leave the last commands in the history either
unset HISTFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment