How can I securely delete/shred a file after I accidentally deleted the file insecurely?

Let's say I have Debian Linux installed on a laptop with a 1000T spinning hard disk (so putting aside wear leveling uncertainty and sfill).

I stored some super-sensitive data to secret.txt. For some reason, I decided I wanted to delete this file, but I accidentally executed rm secret.txt.

Using testdisk, I can see the newly unlinked file. I can restore the deleted file's contents using testdisk, but--afaik--that would just create a new copy of the file (so doing a restore -> shred may not securely wipe the original file's contents from the disk, and it may actually make the issue worse)

How can I actually shred/srm the blocks containing the original file contents of secret.txt following the accidental execution of rm secret.txt?

  • 1
    Since your question mentions an HDD, you can always fill the HDD with a random garbage file, then delete that. – MechMK1 Jul 27 '19 at 13:59
  • Securely wiping files can be very difficult in many file systems, particularly journaling systems such as EXT4. That said, a pretty good but not 100 percent method is to write all or as much as possible unallocated space as was suggested by @MechMK1 then delete the file. Zeroes are faster than random, but either will work. In the correct partition: "dd if=/dev/zero of=bigtemp.dat" , then delete after you run out of space. – user10216038 Jul 27 '19 at 17:24
  • 1
    Note that this HDD fill method is comparable to what shred does. Actually it's better because it's not dependent upon in-place overwites like shred is, but it's time consuming. – user10216038 Jul 27 '19 at 17:33
  • Sorry, I explicitly stated that the disk was 1000T and asked to put aside sfill, which is a utility that fills the disk with random data. Surely, there must be some way to use testdisk or similar to find the exact location of the unlinked original file, then pass that info to some other utility like shred or srm -- instructing it where to securely (over)write the data at the given location.. – Michael Altfield Jul 30 '19 at 3:56
  • 1
    How about relinking it and then shredding? serverfault.com/questions/168909/relinking-a-deleted-file – RedS Sep 18 '19 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.