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