Skip to content

Instantly share code, notes, and snippets.

@weavenet
Created January 6, 2012 21:03
Show Gist options
  • Save weavenet/1572391 to your computer and use it in GitHub Desktop.
Save weavenet/1572391 to your computer and use it in GitHub Desktop.
Script to cleanup RHEL5 instance before creating AMI
#!/bin/bash
USER=ec2-user
echo 'Removing host keys'
sudo /bin/rm -rf /etc/ssh/ssh_host*_key*
echo 'Removing ec2-user'
userdel -f $USER ; /bin/rm -rf /home/$USER
echo 'Cleaning up /var/log'
/bin/cp /dev/null /var/log/secure
/bin/cp /dev/null /var/log/messages
/bin/cp /dev/null /var/log/dmesg
/bin/cp /dev/null /var/log/wtmp
/bin/cp /dev/null /var/log/lastlog
/bin/cp /dev/null /var/log/cron
/bin/rm /var/log/*.log
echo 'Removing faillog'
/usr/bin/faillog -r
echo 'Removing bash_history'
export HISTSIZE=0
/bin/rm /root/.bash_history
echo 'Removing everything from /root'
/bin/rm -r /root/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment