Skip to content

Instantly share code, notes, and snippets.

@zc640618
Forked from mortn/vm-clean-up.sh
Created October 21, 2017 13:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zc640618/64e3a468b24b3d619aae0909864da120 to your computer and use it in GitHub Desktop.
Save zc640618/64e3a468b24b3d619aae0909864da120 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