How to Securely Delete Files on Linux

Share
  • June 21, 2019

Biehler Michael/Shutterstock.com

Shred old data files for the same reason you shred old paper documents. We tell you what you need to know about securely deleting Linux files. This tutorial covers the shred command and the secure-delete suite of utilities.

Deleted Files Are Normally Recoverable

Deleting a file doesn’t actually remove it from your hard drive. It’s all down to the way your filesystem uses inodes. These are the data structures within the filesystem that hold the metadata regarding the files. The name of the file, its position on the hard drive, what attributes and permissions it has, and so on are all stored within an inode. A directory is no more than a file itself. One that holds the names and inode numbers of the files that the directory contains.

When you delete a file with rm, the filesystem frees up the appropriate inode and adjusts the directory file. This marks the space on the hard drive that the file used to occupy as unused. Imagine you walk into a library and go through the card index, find a book’s catalog card, and rip it up. The book is still on the shelf. It’s just harder to find.

In other words, the space that was used by the file is now free to be used by other files. But the contents of the old file still sit in that space. Until that space is overwritten, there is a good chance that file can be retrieved.

But completely getting rid of a file isn’t as straightforward as simply overwriting them. As we shall see.

Don’t Do This With SSD’s

These techniques are for traditional electro-mechanical hard disk drives (HDD), and should not be used with solid state drives (SSD). It won’t work and will cause extra writes and unnecessary wear to your SSD. To securely erase data from an SSD, you should use the utility provided by the manufacturer of your SSD.

RELATED: How to Delete Files and Directories in the Linux Terminal

The shred Command

shred is designed to perform the overwriting for you so a deleted file cannot be recovered. It is included in all of the Linux distributions that were tested during the research for this article, including Ubuntu, Fedora, and Manjaro.

In this example, we’re going to be working in a directory called ~/research, which contains many text files. It also contains some other directories which in turn contain other files. We’re going to assume these files are sensitive and must be erased entirely from the hard drive.

Read the remaining 82 paragraphs

Source : How to Securely Delete Files on Linux