Skip to content

Instantly share code, notes, and snippets.

@tkuennen
Last active July 12, 2018 23:23
Show Gist options
  • Select an option

  • Save tkuennen/b00a42ddc5895f07b3f051e41064d3d0 to your computer and use it in GitHub Desktop.

Select an option

Save tkuennen/b00a42ddc5895f07b3f051e41064d3d0 to your computer and use it in GitHub Desktop.
cleaner
#!/bin/bash
# _ _ _ _ _ _
#| |_ ___ _ __ ___ _ __ | (_) |_(_)_______ ___| |__
#| __/ _ \ '_ ` _ \| '_ \| | | __| |_ / _ \ / __| '_ \
#| || __/ | | | | | |_) | | | |_| |/ / __/_\__ \ | | |
# \__\___|_| |_| |_| .__/|_|_|\__|_/___\___(_)___/_| |_|
# |_|
# Cleans up a system to turn it into a clean template
# curl https://git.io/vNesO |bash
# Stop services for cleanup
service rsyslog stop
# Clear audit logs
if [ -f /var/log/audit/audit.log ]; then
cat /dev/null > /var/log/audit/audit.log
fi
if [ -f /var/log/wtmp ]; then
cat /dev/null > /var/log/wtmp
fi
if [ -f /var/log/lastlog ]; then
cat /dev/null > /var/log/lastlog
fi
# Cleanup persistent udev rules
if [ -f /etc/udev/rules.d/70-persistent-net.rules ]; then
rm /etc/udev/rules.d/70-persistent-net.rules
fi
# Cleanup /tmp directories
rm -rf /tmp/*
rm -rf /var/tmp/*
# Cleanup current ssh keys
rm -f /etc/ssh/ssh_host_*
# Add check for ssh keys on reboot…regenerate if neccessary
sed -i -e ‘s|exit 0||’ /etc/rc.local
sed -i -e ‘s|.*test -f /etc/ssh/ssh_host_dsa_key.*||’ /etc/rc.local
bash -c ‘echo “test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server” >> /etc/rc.local’
bash -c ‘echo “exit 0” >> /etc/rc.local’
# Reset hostname
cat /dev/null > /etc/hostname
# Cleanup yum repositories
yum clean all
rm -rf /var/cache/yum
# Cleanup shell history
history -w
history -c
# Cleanup Firefox
rm -rf ~/.mozilla
# Cleanup Chrome
rm -rf ~/.config/google-chrome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment