I want to delete a file on a linux ext4 file system such that the disk does not contain the name of the file anywhere on the disk (free space, file system metadata, or anywhere else).
For example, I don't want any trace that a file named "passwords.txt" was ever on the disk.
I have posted this question on superuser in a different form and no one has answered it successfully.
I'd prefer to use /usr/bin/shred
. It works great for removing the data of a file, but the file's name is still visible on the disk. Here's how I'm testing it:
dd if=/dev/zero of=fs bs=1M count=300
hexdump -C fs # verify it's empty
mkfs.ext4 fs
mkdir m
sudo mount fs m
sudo chown -R $USER m
cd m
echo secretkey > passwords.txt
cd ..
sudo umount m
grep secretkey fs # <== shows up as expected
grep passwords.txt fs
strings fs | grep sec
strings fs | grep pass
sudo mount fs m
cd m
/usr/bin/shred -vuz -n 1 passwords.txt
cd ..
sudo umount m
grep secretkey fs # <== does not show up, this is good
grep passwords.txt fs # <== PROBLEM: filename still shows
strings fs | grep sec
strings fs | grep pass # <== problem: still shows up
hexdump -C fs | grep sec
hexdump -C fs | grep pass
And here's the output from the mount
command that shows some of the filesystem's modes:
type ext4 (rw,relatime,data=ordered)
More details for those interested:
Update 1:
Renaming the file from passwords.txt to something random like "asdfasdf.txt" before shredding it does not resolve the problem. When you run /usr/bin/shred
in verbose mode you'll see that it goes through a series of file renames before it truncates/unlinks the file. I assumed that this was shred's way of securely removing traces of the file's name. Does the filesystem need certain modes enabled in order to support this? I'll copy/paste what shred
's output looks like during the file removal:
/usr/bin/shred: passwords.txt: pass 1/2 (random)...
/usr/bin/shred: passwords.txt: pass 2/2 (000000)...
/usr/bin/shred: passwords.txt: removing
/usr/bin/shred: passwords.txt: renamed to 0000000000000
/usr/bin/shred: 0000000000000: renamed to 000000000000
/usr/bin/shred: 000000000000: renamed to 00000000000
/usr/bin/shred: 00000000000: renamed to 0000000000
/usr/bin/shred: 0000000000: renamed to 000000000
/usr/bin/shred: 000000000: renamed to 00000000
/usr/bin/shred: 00000000: renamed to 0000000
/usr/bin/shred: 0000000: renamed to 000000
/usr/bin/shred: 000000: renamed to 00000
/usr/bin/shred: 00000: renamed to 0000
/usr/bin/shred: 0000: renamed to 000
/usr/bin/shred: 000: renamed to 00
/usr/bin/shred: 00: renamed to 0
/usr/bin/shred: passwords.txt: removed