You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

  1. #!/bin/bash
  2. # Ensure /tmp exists and has the proper permissions before
  3. # checking for security updates
  4. # https://github.com/digitalocean/marketplace-partners/issues/94
  5. if [[ ! -d /tmp ]]; then
  6. mkdir /tmp
  7. fi
  8. chmod 1777 /tmp
  9. apt-get -y update
  10. apt-get -y upgrade
  11. rm -rf /tmp/* /var/tmp/*
  12. history -c
  13. cat /dev/null > /root/.bash_history
  14. unset HISTFILE
  15. apt-get -y autoremove
  16. apt-get -y autoclean
  17. find /var/log -mtime -1 -type f -exec truncate -s 0 {} \;
  18. rm -rf /var/log/*.gz /var/log/*.[0-9] /var/log/*-????????
  19. rm -rf /var/lib/cloud/instances/*
  20. rm -f /root/.ssh/authorized_keys /etc/ssh/*key*
  21. touch /etc/ssh/revoked_keys
  22. chmod 600 /etc/ssh/revoked_keys
  23. # Securely erase the unused portion of the filesystem
  24. GREEN='\033[0;32m'
  25. NC='\033[0m'
  26. printf "\n${GREEN}Writing zeros to the remaining disk space to securely
  27. erase the unused portion of the file system.
  28. Depending on your disk size this may take several minutes.
  29. The secure erase will complete successfully when you see:${NC}
  30. dd: writing to '/zerofile': No space left on device\n
  31. Beginning secure erase now\n"
  32. dd if=/dev/zero of=/zerofile &
  33. PID=$!
  34. while [ -d /proc/$PID ]
  35. do
  36. printf "."
  37. sleep 5
  38. done
  39. sync; rm /zerofile; sync
  40. cat /dev/null > /var/log/lastlog; cat /dev/null > /var/log/wtmp