Skip to content

Instantly share code, notes, and snippets.

@jdevera
Forked from mortn/vm-clean-up.sh
Last active May 18, 2024 18:39
Show Gist options
  • Save jdevera/06c396b7d6a988f145e1c40c0bd96a06 to your computer and use it in GitHub Desktop.
Save jdevera/06c396b7d6a988f145e1c40c0bd96a06 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
# 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/*
rm -rvf /var/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