kvz.io
Published on

Delete Files Securely With Shred

Authors
  • avatar
    Name
    Kevin van Zonneveld
    Twitter
    @kvz

Deleting a file or reformatting a disk does not destroy your sensitive data. The data can easily be undeleted. That's a good thing if you accidentally throw something away, but what if you're trying to destroy financial data, bank account passwords, or classified company information. What if you want to clean your computer before selling it for instance?

In this article you will learn how to use a very powerful tool, so be careful, because you could totally mess up your system. I currently use Ubuntu, but this article should work for pretty much any distribution.

About Shred

To make sure the data is unrecoverable by anyone, it needs to be overwritten. Ubuntu has got a standard tool for this called shred, you will probably find it preinstalled on your distribution as well.

The shred command lets you delete files or entire hard drives permanently by overwriting the data with random gibberish many times (25 by default). This totally destroys the original data and makes it almost impossible to recover.

Using Shred

Shred Files

For shredding files you can run shred like this:

$ shred -z -u -n200 /home/kevin/company_info/*
  • -z overwrite with zero's the last time, to mask the shred process.
  • -u means delete when you're done overwriting
  • -n200 means overwrite 200 times

Shred Drives

Some things that I'm going to change for this operation:

  • Overwriting 200 times might take too long when overwriting an entire drive, so let's overwrite it 10 times.
  • The device itself can't be deleted so the u argument has to leave.
  • We need to replace the /home/kevin/company_info/ with your device name, which you could look up by typing df.
  • You can always concatenate arguments so I'm going to do that as well.

So now the command could look something like this:

$ shred -zn10 /dev/hda

This will totally erase everything on your hard drive. It's best to do this from a Live CD, otherwise during the first run, it will begin missing some essential system files (that of course are being overwritten) and you don't want to crash the system before totally destroying all data.

Final Remarks

Shred works best on an entire disk because journaling filesystems may store duplicate data in other places on the disk that shred won't delete.

Legacy Comments (10)

These comments were imported from the previous blog system (Disqus).

Zigzo ZLinks
Zigzo ZLinks·

Damn, i had no idea ubuntu came with this! Thanks (AGAIN) for another great article.

I like how concise this one was.

Kevin
Kevin·

Hi Zigzo ZLinks,

I really do try to keep all of my articles brief and precise but unfortunately I\'m a technician and no writer so sometimes I get carried away a bit ;)

But thanks, means a lot to hear someone saying I got it right this time! :)

Bealer
Bealer·

Nice, just what I was looking for. Well laid out and to the point.

Am enjoying Ubuntu. Would be nice if there was a gui for shred. Anyone know of one?

Jerry Wooten
Jerry Wooten·

Following your example on shredding a hard drive.
Acer laptop-Vista installed(can\'t stand)
Ubuntu newbie- Booted with Ubuntu 7.10 live CD

Opened terminal-typed after ubuntu@ubuntu:~$
shred -zn10 /dev/sda (screen popped up telling me I had to use sudo command)
typed sudo shred -zn10 /dev/sda (enter)
blinking cursor comes up on next line, is this working
Hear CD drive noise occasionally.
Could you tell me approx how long or did I do something wrong & need to start over.

Kevin
Kevin·

@ Jerry Wooten: You could use:
shred -zvn1 /dev/sda

Shredding can take a very long time, so let\'s first run it (n1) once. And show progress (v) to see what\'s happening.

Jerry Wooten
Jerry Wooten·

Thanks for your help, I shut it down & tried to open Vista, I couldn\'t, so I guessed it worked partitally. Read somemore a found out (v), restarted again and everything seems to be working. At it for 2 hrs & I\'m at pass 3/11 71%.

Kevin
Kevin·

@ Jerry Wooten: Remember if you just want to get rid of Vista there are easier ways. This is if your really want to destroy your data so it can never be restored by anyone. So this is mostly used for company critical documents or private data before e.g. selling a computer to someone else.

jerry wooten
jerry wooten·

I need to return this Dell to my boss, want to return it in the original condition, just XP Home Edition,(Have restore CD). I put a slave drive with XP Pro & Ubuntu 6.06, have grub to select OS.

Disk /dev/hda: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 1 4 32098+ de Dell Utility
/dev/hda2 * 5 9228 74091780 7 HPFS/NTFS
/dev/hda3 9229 9725 3992152+ db CP/M / CTOS / ...

Disk /dev/hdb: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdb1 * 1 1912 15358108+ 7 HPFS/NTFS
/dev/hdb2 1913 1974 498015 82 Linux swap / Solaris
/dev/hdb3 1975 2096 979965 83 Linux
/dev/hdb4 2097 4865 22241992+ 8e Linux LVM

Could you give me steps on how to get back to 1 80 HD with XP home edition

Thanks in advance.

Kevin
Kevin·

@ jerry wooten: For that purpose, just format C: with the xp install cd.

Green
Green·

Hi

I use shred a lot i my job and I usually type:
[CODE="Javascript"] sudo shred -vf /dev/sda [/CODE]
This way it erases 3 times (default) and I can see what's going on with Verbose mode (v). I leave out -z since I don't need to mask that the drive has been overwritten. /Green