Monday, 4 July 2011

Deleting Files Securely.

It's no secret that deleting files from a directory doesn't actually erase the files from a hard-drive: it simply marks the disk space as writeable (or empty) and removes any links to the file from the file-tree. For most purposes this is sufficient, but what about those sensitive bank account records and other files that you'd rather not leave hanging around?

Fortunately, Ubuntu ships with the GNU core utilities package which contains the shred command to overwrite a file and effectively destroy its data1.

Let's say that you have a text file called test.txt in the your /home/USR_Name directory that you want to obliterate. Open a terminal and type:

$ shred -u -z -v -n [N] /home/[USR_NAME]/test.txt

-uTruncates & removes the file after overwriting.
-zAdds a final overwrite with zeros to obscure the shredding process.
-vShows the progress (verbose output) of the operation in the terminal window.
-nThe number [N] of iterations instead of the default.

So, to shred the test.txt file from my /home/[USR_NAME] directory with 30 iterations:

$ shred -u -z -v -n 30 /home/jogga/test.txt

The command can manage multiple files and wildcards. For instance, if you want to delete all .jpg files in a directory; change to the directory (cd /home/[USR_NAME]/directory) and type:

$ shred -u -z -v -n [N] ./*.jpg

However, you should exercise caution when destroying multiple files (or, in fact, when destroying individual files)!

Sources & References:


1 There are limitations to this claim: some file systems negate the efficacy of the shred command and you should read the man page to ensure that this form of data obliteration meets your needs. In Ubuntu, the ext3 file system is particularly problematic.

No comments:

Post a Comment