Linux security

How to encrypt and decrypt directory with gpgdir script

gpgdir is a perl script that uses the CPAN GnuPG::Interface module to encrypt and decrypt directories using a gpg key specified in ~/.gpgdirrc.  This script will help you to encrypt and decrypt directories using  a GPG key. It supports recursively descending through a directory in order to make sure it encryptsor decrypts every file in a target directory and all of its subdirectories.

Installation and configuration of gpgdir on Ubuntu:

  • Download the binary file, PGP key and verify signature
mkdir gpgdir
gpg --import public_key
gpg --verify gpgdir-1.9.5.tar.bz2.asc
  • Lets install the gpgdir script on Ubuntu box
tar xfj gpgdir-1.9.5.tar.bz2
cd gpgdir-1.9.5
  • We have to configure gpgdir for use with your default GPG key
vi /usr/local/src/gpgdir
  • Make a change in the conf file .. uncomment line “default_key and save
# Uncomment to use the GnuPG default key defined in ~/.gnupg/options:
# If you want to specify manually the right key enter it on next line
use_key 000BBD1XX

This complete the installation and configuration of gpgdir. You can now use it to encrypt or decrypt directories and you can do it manually or you can write simple bash script.

Man Page and usage of the gpgdir

Simply usage of Encrypt or Decrypt directory

gpgdir --encrypt {directory}
gpgdir --decrypt {directory}
## Encrypt directory and wipe out the original once encrypted
gpg -W -e {directory}

This could be integrated nicely into simple script.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.