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

#!/bin/bash
gpg –passphrase  “$1” &&
rm “$1”

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

Another for authenticating

#!/bin/bash
gpg –passphrase $password  “$1” &&
rm “$1”

Again the usage would be ./authenticate.sh /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

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

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/password.sh %f

The appearance conditions can be everything except for directories.

To authenticate the script

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

and the custom action script would be

Name=Authenticate
Description=Authenticate A Password Protected File
Command=/path/to/authenticate.sh %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.

Advertisements
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:

WordPress.com Logo

You are commenting using your WordPress.com 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

Archives
Categories

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

Join 69 other followers

%d bloggers like this: