Complete destruction of your Linux server

Source: Internet
Author: User

When we rent a Linux cloud host, if the service is about to expire, how do you completely destroy the Linux cloud host you rented? The shell script reproduced in this article can completely destroy the Linux cloud host and destroy the data by performing n overwrite write operations on the currently used hard drive (of course, it has no effect on backups and snapshots).

The following is the shell script content:

#!/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  ([ Email protected]) #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 ynif [ -z  $yn  ] | |  [  $yn  !=  "yes"  ]; then    echo  "aborting"      exit 1fiecho -n  "how many zeroing passes? "; read  zeropassif [ -z  $zeropass  ] | |  [  $zeropass  -lt 1 ]; then    echo  "Invalid number  of passes specified. aborting. "     exit 1fiecho -n  "automatically shutdown? [yes|no] ";  read asdecho  "Okay, here we go ..." echo  "making and populating  ramdisk  (512MB) ... "mkdir -p /var/ramdiskmount -t tmpfs none /var/ Ramdisk -o size=512m # you may need to adjust this depending  on the amount of ram in the boxmkdir -p /var/ramdisk/var/runfor f in dev bin lib lib64  sbin etc; do    cp -pr /$f  /var/ramdiskdonecp -pr /var/ run /var/ramdisk/varecho  "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  stopdoneecho  "Placing zeroing script" echo  "#!/bin/bash"  >  $zeroscriptfor   i in  ' fdisk -l | grep disk | awk  ' {print$2} '  | sed &NBSP;-E&NBSP;S/://&NBSP;|&NBSP;GREP&NBSP;-V&NBSP;/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 suredoneecho  "Echo \" Disk (s) $DU  have been zeroed  $zeropass  times\ ""  >> $ zeroscriptif [  $asd  =  ' yes '  ]; then    echo  ' echo  \ "Shutting down...\" " >>  $zeroscript     echo " sleep 5  && /sbin/poweroff -n -d -f " >>  $zeroscriptfichmod  +x $ zeroscriptecho  "Turning off swap ..."  && swapoff -aecho  "Entering  chroot "chroot /var/ramdisk /' basename  $zeroscript '

Save the shell as a shell file (for example: destroylinuxos.sh) and grant the executable permission (chmod +x destroylinuxos.sh), when executing the script, answer "Yes, 2, yes" in turn Will really start to completely destroy the Linux host program, where the first yes to agree to start the execution of the shell (Prevent mis-execution), "2" for the specified "overwrite write" the number of writes (need greater than 0), the last yes means to complete the "overwrite write" operation after the direct shutdown, if the answer is not yes will not shutdown.

Analysis of the above script shows that first (1) Create a memory disk in memory (you can modify the Size property value of the Mount statement in the above script according to the disk occupancy of the relevant folder of the current system before executing the above script) ; then (2) Copy the relevant files from the corresponding directory of the current system to the memory disk, then (3) Start to stop the start-up service in the current system (can be modified according to your host service situation, be careful not to stop the sshd service); finally (4) Start outputting the relevant shell script to the variable Zeroscript the specified script file (the script is used to (a) finish overwriting the disk [i.e. destroying the disk data], depending on the third input (b) whether to shut down directly); After completing the previous four operations, (5) switching the system root path to the memory disk and executing the variable The script file specified in the Zeroscript. Over ...


PS: The script above comes from the article "How to Empty your Linux server".







Complete destruction of your Linux server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.