A Beginner's Guide to GnuPG: Encrypting and Signing Your Files and Emails
GnuPG is a free and open-source implementation of the OpenPGP standard, which allows you to encrypt and sign data securely. It works on Windows, macOS, and Linux, making it a versatile tool for protecting your communications.
Before we begin, make sure you have GnuPG installed:
sudo apt install gnupg
brew install gnupg
Once installed, verify it’s working:
gpg --version
GnuPG uses public-key cryptography, meaning you have a private key (kept secret) and a public key (shared with others).
To generate a new key pair:
gpg --full-generate-key
Follow the prompts:
Once done, list your keys:
gpg --list-keys
To let others send you encrypted messages, they’ll need your public key. Export it with:
gpg --export --armor your-email@example.com > public_key.asc
The --armor
flag saves it in readable ASCII format.
You can share public_key.asc
or upload it to a keyserver:
gpg --keyserver hkps://keys.openpgp.org --send-keys YOUR_KEY_ID
To encrypt a file (secret.txt
) for someone else (using their public key):
gpg --encrypt --recipient their-email@example.com secret.txt
This creates secret.txt.gpg
.
To decrypt a file:
gpg --decrypt secret.txt.gpg > decrypted.txt
You’ll be prompted for your passphrase.
gpg --sign --armor --output signature.asc document.txt
This creates a detached signature (signature.asc
) that others can verify.
gpg --verify signature.asc document.txt
If the signature is valid, you’ll see a confirmation.
Many email clients (Thunderbird, Outlook with plugins) support GnuPG. For CLI users:
gpg --encrypt --sign --armor --recipient friend@example.com email.txt
gpg --decrypt encrypted_email.asc
GnuPG is an essential tool for securing your digital communications. With just a few commands, you can:
Generate and manage encryption keys
Encrypt and decrypt files
Sign and verify documents
For more advanced usage (key revocation, subkeys), check the official GnuPG docs.
Have questions? Drop them in the comments below!