Coder, Entrepreneur, Blogger, and Coffee Addict
Sometimes we have sensitive data that we want to get rid of. Since deleting a file doesn’t actually prevent it from being recovered we need to do some extra steps to ensure that it can’t be recovered. In this post we will use DD to complete this task. DD is often the tool digital forensics use to duplicate hard drives we will use it for a more destructive use so that our data can’t be recovered.
If you looking for a way to wipe an entire hard drive check out, Wiping a Hard Drive with DD.
Before deleting the sensitive file we will write over top of it with random characters.
First we find out how many characters we have to write over:
$ ls -l
This will list the directory contents. Find your file and remember or write down the byte size. It might look like this:
-rw-r--r-- 1 mark mark 21 Apr 15 22:40 test.txt
In this case the we have 21 bytes
Now that we know we have 21 bytes to write over we will use this command:
dd if=/dev/urandom of=test.txt bs=21 count=1 conv=notrunc
Now that the file you want to securely wipe has been written over it is much harder for someone to retrieve it. As of right now it is pretty much impossible to recover the file using software. You would have to use an expensive machine and physically look through the hard drive for the data. Even then you are not guaranteed to be able to find/recover the data. The only thing left to do is actually delete it.
rm test.txt
If you want to be really sure your data is gone you will need to write over the file 7 times. This is the current Department of Defense procedure for wiping sensitive data.
for ((n=1;n<8;n++)); do COMMAND; done;
This is the standard one line for loop that will repeat a command. The above command will repeat 7 times. Just replace the COMMAND part with your dd command.
© 2011 All rights reserved
a much better tool comes stock on most linux these days: shred
SHRED(1) User Commands SHRED(1)
NAME
shred – overwrite a file to hide its contents, and optionally delete it
SYNOPSIS
shred [OPTIONS] FILE [...]
DESCRIPTION
Overwrite the specified FILE(s) repeatedly, in order to make it harder for even very expensive hardware probing to recover the data.
Mandatory arguments to long options are mandatory for short options too.