Skip to content

Instantly share code, notes, and snippets.

@mstaack
Created August 11, 2018 14:01
Show Gist options
  • Save mstaack/b850afc831fd576814c84bd3de134090 to your computer and use it in GitHub Desktop.
Save mstaack/b850afc831fd576814c84bd3de134090 to your computer and use it in GitHub Desktop.
Cleanup Ubuntu
#!/bin/bash
# Stop rsyslog to clean up logs
service rsyslog stop
# Cleanup all logs
cat /dev/null > /var/log/audit/audit.log
cat /dev/null > /var/log/wtmp
cat /dev/null > /var/log/lastlog
#cleanup persistent udev rules
rm /etc/udev/rules.d/70-persistent-net.rules
#cleanup /tmp directories
rm -rf /tmp/*
rm -rf /var/tmp/*
#cleanup current ssh keys
rm -f /etc/ssh/ssh_host_*
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'
# Clear hostname
cat /dev/null > /etc/hostname
# Cleanup apt
apt-get clean
#cleanup shell history
history -w
history -c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment