Every time you delete a file from your Linux system using the shift + delete or rm command, it doesn’t actually permanently and securely delete the file from the hard disk. When you delete a file with the rm command, the file system just frees up the appropriate inode but the contents of the old file are still in that space until it is overwritten which pave a way to recover the files.
The space that was used by the file that you deleted is now free to be used by other new files. But the contents of the old files are still in the hard disk, Until and unless that space is overwritten by something else, so there is a good chance that the file can be recovered by anyone (maybe by some data thieves) with good knowledge of recovering data. It is like removing the index page of a book, where the chapters are still there, it just becomes much hard to find, but we can find it.
Tools to Securely Delete Files from Linux
Method 1: Using Shred
Shred will help you to overwrite a deleted file, so it becomes difficult to recover it. It is like tearing a paper into as many pieces as you want or overwriting over the paper so that it becomes impossible to find out the original data.
In the above output, the meaning of the letters are:
- -u: deallocates and removes file after overwriting
- -v: enables the display of operation progress
- -z: adds a final overwrite with zeros to hide shredding
- -n: total number of times the file content will be overwritten(I gave 6).
Method 2: Secure-Delete:
Secure-delete is a command containing a set of secure file deletion tools containing srm (secure_deletion) tool which is used to delete or overwrite the files securely in Linux.
At first, we have to install it by typing:
sudo apt-get install secure-delete
There is a total of 4 different types of tools consisting of this whole package and each of them performs a different type of securely delete operation. They are as follows:-
- srm : It is a secure rm that is used to erase files by overwriting their hard disk space and deleting them.
- sfill : It is used to overwrite free space on the hard disk.
- sswap : It is used to overwrite swap space.
- sdmem : It is used to wipe the RAM Once secure-delete is installed.
# srm Command:
srm command deletes anything just like rm command but securely i.e by overwriting the file and its inode with random bytes. The larger the file, the longer it takes to wipe and rewrite it.
Type srm man to get more information:
Method 3: Using Wipe.
The Linux wipe command allows us to securely erase data from our hard disk permanently. The wipe command erases files from magnetic memory and rewrites the space repeatedly and wipe away the caches which make the data nearly impossible to be recovered.
At first, we have to install a wipe:
Now you can use wipe for secure deletion
To know more about each function check wipe -h:
Method 4: Using dd:
dd command is especially used to convert or copy files. We can use this command to completely overwrite your hard drive with zeros, but DD will not zero a drive currently in use
The syntax is :
- dd if=<source> of=<target> [Options]
In the above menu:
- lsblk: Lists all the disks
- /dev/urandom (input): The random data used for overwriting
- /dev/sda (output): the disk that will be overwritten. This disk will be replaced with random garbage data.
See the help menu of the “dd” command for more details: