#!/bin/sh | |
rm -rf /tmp/* | |
rm -f /etc/ssh/ssh_host_* | |
if [ -d /var/log ]; then | |
find /var/log -type f -print | xargs -L1 /bin/cp /dev/null | |
fi | |
if [ -d /var/spool/mail ]; then | |
find /var/spool/mail -type f -print | xargs -L1 /bin/cp /dev/null | |
fi | |
/bin/cp /dev/null /root/.ssh/authorized_keys | |
/bin/cp /dev/null /root/.bash_history | |
if [ -f /root/.mysql_history ]; then | |
/bin/cp /dev/null /root/.mysql_history | |
fi | |
if [ -d /home/ec2-user ]; then | |
/bin/cp /dev/null /home/ec2-user/.ssh/authorized_keys | |
/bin/cp /dev/null /home/ec2-user/.bash_history | |
if [ -f /home/ec2-user/.mysql_history ]; then | |
/bin/cp /dev/null /home/ec2-user/.mysql_history | |
fi | |
fi | |
history -c | |
echo "clear!" |
- /var/log 以下のファイルを /dev/null で上書き
- /var/spool/mail 以下のファイルを(略)
- /root 以下の .ssh/authorized_keys, .bash_history, .mysql_history を(略)
- (あれば) /home/ec2-user 以下の .ssh/authorized_keys, .bash_history, .mysql_history を(略)
- /tmp/*, /etc/ssh/ssh_host_* を削除
をやるので、最低限必要なことはこれで足りるはず
参考: cloudpackブログ: 公開AMIを作成する直前で行っていること
せっかちなあなたには
# curl -L clear.ninjax.cc | bash; history -c
authorized_keys 消すから、この作業やったら、そのインスタンスにはログインできなくなるよ