Posted in Information Technology

3 Ways to Permanently and Securely Delete ‘Files and Directories’ in Linux

In most cases the means we use to delete a file from our computers such as using Delete key, Trash files or rm command, which do not permanently and securely remove the file from the hard disk (or any storage media).

The file is simply hidden from users and it resides somewhere on the hard disk. It can be recovered by data thieves, law enforcement or other threats.

 

Assuming a file contains classified or secret content such as usernames and passwords of a security system, an attacker with the necessary knowledge and skills can easily recover a deleted copy of the file and access these user credentials (and you can probably guess the aftermath of such as scenario).

In this article, we will explain a number of command line tools for permanently and securely deleting files in Linux.

1. Shred – Overwrite a File to Hide Content

shred overwrites a file to hide its contents, and can optionally delete it as well.

$ shred -zvu -n  5 passwords.list

In the command below, the options:

  1. -z – adds a final overwrite with zeros to hide shredding
  2. -v – enables display of operation progress
  3. -u – truncates and removes file after overwriting
  4. -n – specifies number of times to overwrite file content (the default is 3)

shred - overwrite a file to hide its contents

You can find more usage options and information in the shred man page:

$ man shred

2. Wipe – Securely Erase Files in Linux

A Linux wipe command securely erases files from magnetic memory and thereby making it impossible to recover deleted files or directory content.

First, you need to install wipe tool in order to it, run the appropriate command below:

$ sudo apt-get install wipe   [On Debian and its derivatives]
$ sudo yum install wipe       [On RedHat based systems]

The following command will destroy everything under the directory private.

$ wipe -rfi private/*

where the flags used:

  1. -r – tells wipe to recurse into subdirectories
  2. -f – enables forced deletion and disable confirmation query
  3. -i – shows progress of deletion process

Wipe - Securely Erase Files in Linux

Note: Wipe only works reliably on magnetic memory, therefore use the other methods for solid state disks (memory).

Read through the wipe man page for additional usage options and instructions:

$ man wipe

3. Secure-deletetion Toolkit for Linux

Secure-delete is a collection of secure file deletion tools, that contains srm (secure_deletion) tool, which is used to remove files securely.

First you need to install it using the relevant command below:

$ sudo apt-get install secure-delete   [On Debian and its derivatives]
$ sudo yum install secure-delete       [On RedHat based systems]

Once installed, you can use srm tool to remove files or directories securely on a Linux system as follows.

$ srm -vz private/*

where the options used:

  1. -v – enables verbose mode
  2. -z – wipes the last write with zeros instead of random data

srm - Securely Delete Files in Linux

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s