PGP/GPG on Linux

Linux is a great platform that has many advantages over a windows based platform, and one of those advantages is PGP (Pretty Good Privacy) available on a base install. In 1991 Phil Zimmermann created the first version of PGP encryption which allows for cryptographic privacy and authentication for data communication. It is widely used for securing email, but can be used to secure texts, files, directories, hard drives, and is now being used to encrypt entire computer systems.

To use PGP, you need to create or import a certificate into the keystore. The keys can be in DSA or RSA formats and have lengths of 1024 to 4096 bits on most systems. The certificates can also be set to never expire or be set to expire within a certain timeframe.

To List Keys in the Keystore:
pgp –list-keys

To Generate a new key:
gpg –gen-key

To Import an existing key:
gpg –import ~/keyfilename.gpg

To Import an existing key secret key:
gpg –allow-secret-key-import –import ~/secretkeyfilename.gpg

When you need to export the data, you will need to remember that there is two parts to the key, the public key, and the secret key. When a client wants to encrypt data for you they will require the public key.

To Export an existing key and secret key:
gpg –output keyfilename_public.gpg –armor –export keyname
gpg –output keyfilename_secret.gpg –armor –export-secret-key keyname

To Encrypt/Decrypt a file, remember the passphrase used, if forgotten your data will remain encrypted forever.

To Encrypt a file:
gpg -c filenametoencrypt (you will be asked for the passphrase to encrypt with).
gpg –yes –passphrase={YourPassPhrase} -c filenametoencrypt

To Decrypt a file:
gpg filenametodecrypt (you will be asked for the passphrase used to encrypt with).
gpg –yes –passphrase={YourPassPhrase} filenametodecrypt