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:
-z– adds a final overwrite with zeros to hide shredding
-v– enables display of operation progress
-u– truncates and removes file after overwriting
-n– specifies number of times to overwrite file content (the default is 3)
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:
-r– tells wipe to recurse into subdirectories
-f– enables forced deletion and disable confirmation query
-i– shows progress of deletion process
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:
-v– enables verbose mode
-z– wipes the last write with zeros instead of random data