完全销毁你的Linux服务器

当咱们租用Linux云主机时,若是服务即将到期,怎样完全销毁你所租用Linux云主机呢?本文所转载的shell脚本能够很是完全地销毁Linux云主机,而且对当前所使用硬盘采用执行N次覆盖写操做对数据进行完全破坏(固然,对备份和快照没有做用)。
html

如下是shell脚本内容:c++

#!/bin/bash
#
# This script will absolutely kill a RHEL/CentOS/Fedora server. Use with extreme caution.
# Tested with several CentOS/RHEL versions only. Run as root user.
# 10.20.11 Paul Venezia (pvenezia@pvenezia.com)
#

zeroscript="/var/ramdisk/zeroscript.sh"

echo "*******************************************************************
** This will permanently kill this Linux system and erase every **
** local disk and filesystem. In other words, you better be **
** REALLY REALLY SURE you want to do this on this system. **
*******************************************************************"

echo -n "Are you absolutely sure you want to do this? [yes|no]: "; read yn

if [ -z $yn ] || [ $yn != "yes" ]; then
    echo "Aborting"
    exit 1
fi

echo -n "How many zeroing passes? "; read zeropass

if [ -z $zeropass ] || [ $zeropass -lt 1 ]; then
    echo "Invalid number of passes specified. Aborting."
    exit 1
fi

echo -n "Automatically shutdown? [yes|no] "; read asd
echo "Okay, here we go..."
echo "Making and populating ramdisk (512MB)..."

mkdir -p /var/ramdisk

mount -t tmpfs none /var/ramdisk -o size=512m # You may need to adjust this depending on the amount of RAM in the box

mkdir -p /var/ramdisk/var/run

for f in dev bin lib lib64 sbin etc; do
    cp -pr /$f /var/ramdisk
done

cp -pr /var/run /var/ramdisk/var

echo "Stopping services, it's probably safe to ignore any errors..."

for s in httpd acpid anacron atd auditd autofs avahi-daemon bluetooth cpuspeed crond cups firstboot gpm haldaemon hidd hplip irqbalance iscsi iscsid kudzu lm_sensors lvm2-monitor mcstrans mdmonitor messagebus microcode_ctl netfs nfslock pcscd portmap rawdevices readahead_early restorecond rpcgssd rpcidmapd sendmail smartd sshd syslog vmware-tools xfs yum-updatesd; do
    service $s stop
done

echo "Placing zeroing script..."

echo "#!/bin/bash" > $zeroscript

for i in `fdisk -l | grep Disk | awk '{print$2}' | sed -e s/:// | grep -v /dev/md`; do

    DU=$DU" "$i
    DSK=`basename $i`
    BLKS=$((`grep -w $DSK /proc/partitions | awk '{print$3}'` * 2)) # account for 512/1k blocksizes
    BS=512

    echo "echo \"Zeroing $i (dd if=/dev/zero of=$i bs=$BS count=$BLKS) ...\"" >> $zeroscript

    for (( c=1; c<=$zeropass; c++ )); do
        echo "echo \"Pass $c...\"" >> $zeroscript
        echo "dd if=/dev/zero of=$i bs=$BS count=$BLKS" >> $zeroscript
    done

    echo "dd if=/dev/zero of=$i bs=512 count=1" >> $zeroscript # Just to make sure

done

echo "echo \"Disk(s)$DU have been zeroed $zeropass times\"" >> $zeroscript

if [ $asd = 'yes' ]; then
    echo "echo \"Shutting down...\"" >> $zeroscript
    echo "sleep 5 && /sbin/poweroff -n -d -f" >> $zeroscript
fi

chmod +x $zeroscript

echo "Turning off swap..." && swapoff -a
echo "Entering chroot..."

chroot /var/ramdisk /`basename $zeroscript`

将上述shell保存为shell文件(如:destroyLinuxOS.sh)并授予可执行权限(chmod +x destroyLinuxOS.sh),执行该脚本时,要依次回答 “yes 、 2 、 yes” 才会真正开始完全销毁Linux主机的程序,其中第一个 yes 表示赞成开始执行shell(防止误执行),“2“为指定“覆盖写”的写次数(须要大于0),最后的 yes 表示完成“覆盖写”操做之后直接关机,若是回答不为 yes 则不关机。shell

分析上述脚本可知,首先(1)在内存中建立内存磁盘(可在执行上述脚本前根据当前系统的相关文件夹的磁盘占用状况修改上述脚本中的 mount 语句的 size 属性值为合适大小);而后(2)从当前系统的相应目录中复制相关文件到内存磁盘中;以后(3)开始中止当前系统中的已启动服务(可根据你的主机服务状况进行修改,注意不要中止 sshd 服务);最后(4)开始输出相关shell脚本到变量 zeroscript 指定的脚本文件中(该脚本用来(a)完成对磁盘进行覆盖写操做 [即:销毁磁盘数据],根据第三个输入内容决定(b)是否直接关机);在完成前面四项操做之后,(5)切换系统根路径到内存磁盘,并执行在 变量 zeroscript 中指定的脚本文件。over...bash


PS: 上述脚原本源于《如何将你的Linux服务器清空》文章所转载的内容。
服务器

相关文章
相关标签/搜索