views:

33

answers:

4

I'm writing a bash script that encrypts the data of a folder or file

#!/bin/bash

file_name=$1
tmp_file=/tmp/tmpfile.tar

# tar compress file
tar -cf $tmp_file $file_name;

# encrypt file
gpg -c $tmp_file

# remove temp file
rm -rf $tmp_file $file_name

# mv encrypted file to orignal place
mv ${tmp_file}.gpg $file_name

but the data will still be recoverable by using photorec or similar methods...

Is there a way to ensure the absolute deletion of the original file in bash?

Thank You
Stefan

+2  A: 

you can try srm or wipe

ghostdog74
srm did the trick, thank you
NixNinja
A: 

Can you create a ramdisk to create the temp file in? Alternatively if the data is that sensitive maybe you should be using an encrypted file system?

vickirk
Hey, if someone is going to down vote this at least say why!
vickirk
+2  A: 

I gather it is impossible to just pipe the file into gpg, as you would already have tried that?

ndim
Excellent point, gpg supports reading from stdin.
vickirk
sure, that would be the better sollution, but the i am more concerned with destroying the original file.
NixNinja
But at least that would avoid the temporary file. One file to wipe is better than wiping two.
ndim
yea yea :) thats why i gave you +1, but I wana know about wiping that one file...
NixNinja
+1  A: 

This should also work:

rm -Pf file
freddy