How To Password Protect A File

We all have files we want secure , one easy method is to use the gpg command like this

gpg -c MyFile

To authenticate

gpg Myfile

Which would output

gpg: CAST5 encrypted data
gpg: encrypted with 1 passphrase
File `MyFile’ exists. Overwrite? (y/N) n
Enter new filename

As we can see the command didn’t remove the original file so MyFile and Myfile.gpg both exist , which means we have to remove the original manually an easy solution could be to use a small script to set the password then remove the original file

gpg –passphrase  “$1” &&
rm “$1”

Its usage would be ./ /path/to/file

Another for authenticating

gpg –passphrase $password  “$1” &&
rm “$1”

Again the usage would be ./ /path/to/file

Easy enough , however that would mean entering a terminal and navigate to the directory with the script every time you wanted to encrypt a file , so an easy solution would be use a custom action script for whichever file manager your using .

To Set and Verify the password

pass=$(zenity –entry –text “Password” –hide-text –title “Set Password”);
check=$(zenity –entry –text “Password” –hide-text –title “Verify Password”);
if [ “$pass” = “$check” ]
gpg –passphrase $pass -c “$1” &&
rm “$1”
zenity –error –text=”Passwords do not match”

When setting up the custom action script the name and description can be whatever you would like , something like this;

Name=Password Protect
Description=Password Protect A File
Command=/path/to/ %f

The appearance conditions can be everything except for directories.

To authenticate the script

password=$(zenity –entry –text “Password” –hide-text –title “Enter Password”);
gpg –passphrase $password  “$1” &&
rm “$1”

and the custom action script would be

Description=Authenticate A Password Protected File
Command=/path/to/ %f

The appearance conditions are *.gpg and tick the other files box.

Caution since the scripts are using the rm command it would be wise to test these scripts and custom action scripts on a test file first.

Posted in 01Ben, Authors, Computers, General, General, General Technology, Interesting, Linux, Minimal Tech, Other, Uncategorized

Please feel free to leave a reply.

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 67 other followers

%d bloggers like this: