How to erase hard drive securely

Erase Hard DriveWhen it gets to the time to return your server to your provider, you need to securely remove your files from your server before returning your server, specially if you have sensitive data in there and you do not want the next person who gets the server to be able to access your data using data recovery tools.

Some software packages provide tools to zero write the entire disk after removing your files to make it impossible to recover your data, however if you are looking for a simple option, you can write your own shell script to do it for you by copying a dummy file over and over on a folder in your server until your disk gets full.

This tutorial explains how to erase hard drive securely on a Linux machine, if you are using a Windows, you can create a batch file using similar commands.

1. Backup all of your data, there is no way back so ensure that you have backed up all of your files.

2. Next step is to remove your data including your database files and any sort of sensitive information you may have. You may format your hard disk if you have access to it and then start the following task after formatting your disk, otherwise you can remove all of your files, databases, configuration files, SSH private and public keys ( /root/.ssh folder).

3. Create a dummy file so we can copy it over and over to fill the entire disk, to create a dummy file, you can use the following bash script:

cd /

And copy the following in the file:

for i in {0..10000000}
 echo '0000000000' >> dummy

for a in {1..1000000}
 cp dummy $a

Hit Ctrl+o , Press Enter key and then press Ctrl+x to exit.

Run the following command to generate the dummy file:

sh &

Now you can logout and the server should copy the dummy file to fill the disk. Depending the disk size and processor speed, the time it takes to complete this process may vary. On an Intel quad core processor it took me about 2 hours to finish the task on a 1TB hard disk.

About majid

Software engineer, Web developer and IT graduate. Profile: View My Profile
This entry was posted in Information Technology. Bookmark the permalink.