Linux: Securely erasing a hard drive

I recently did some upgrading to my main desktop computer and my Network Attached Storage.  As a result, I ended up moving around some hard drives and have several hard drives that are no longer in machines.  I’m holding on to most of the hard drives, but some I plan on selling or giving away.  Most haven’t had particularly sensitive information on them.  Even so, there isn’t a good reason to not wipe the hard drives completely before giving them away.  Built into the basic Linux operating system (through the “coreutils” package) is a program that will securely erase hard drives.  Securely erasing hard drives means deleting all the files, then randomly writing 1s and 0s over the entire drive multiple times to make sure that it is very difficult to recover the information that was on the drive (there are still some ways to retrieve data, but only by using very expensive equipment; if you want to insure that data cannot be retrieved, you have to physically destroy the hard drive).  This is good practice if you ever plan on giving a hard drive away that you’ve used, particularly if the hard drive contained sensitive information (e.g., passwords, nude photos of a significant other, etc.).

The Linux utility is “shred.”  Here’s how you’d go about securely erasing a hard drive.  (Based on this website, though this one is very clear as well.)

(1) Connect your hard drive to your system. You could set it up as an internal hard drive, or connect it with an external connector.  Either way, it needs to be connected to your system.  (NOTE: If you’re connecting a hard drive to your system through USB, make sure the hardware you are using to connect the drive to your system can handle the size of your hard drive.  Not all USB hard drive connection hardware is suitable for large (>1 TB) drives.)  You’ll want to make sure that the hard drive is connected, but not mounted.

(2) You need to find out which drive it is (i.e., the drive letter designation).  There are a number of utilities to do this.  You could use a GUI, like KDE Partition Manger, Disks, or GParted.  You can also do this from a terminal using a command like:

fdisk -l

That will list all of your connected drives.  Your drive should have a designation like: /dev/sdx.  The “x” will likely be “a,” “b,” “c,” etc.

(3) Once you’ve got your drive connected to your system and you know what the designation is, now it’s time to shred the disk.  The basic command is:

sudo shred /dev/sdx

That will write random 1s and 0s over the entire disk three times.

(4) However, the shred utility has a number of modifiers that you may find useful.  For instance, if you tack on “-v” it will show you the progress.  This is particularly helpful if you have a very large drive, since this process can take days to complete.  You can also add “-f”, which will force permission changes to allow writing if necessary.  Adding “-u” will erase any files that are overwritten.  And you can add “-z” to add a final overwrite with zeros to hide the shredding that you did.  Thus, the command would look like this:

sudo shred -vfuz /dev/sdx

(5) Finally, if you want to be extra cautious, you can specify the number of overwrites by adding “-n X” with X being the number of times you want to overwrite random data on the drive.  This command:

sudo shred -vfuz -n 10 /dev/sdx

would overwrite random data ten (10) times, then finish with a write of all zeros (the “-z”), so it would overwrite the entire drive 11 times.  Depending on the size of your drive, that could take a very, very long time (several days or a week).  One wipe is likely sufficient; three is more than sufficient for most people.  If you’re really worried about people accessing your data, shred the drive three times, then physically destroy the drive with a hammer.