How to Use GPG

Written on 14 Aug 2025 by zacoons

Table of Contents

On the contact page of some people's personal websites you will see a link to their public PGP key.

## What is a public PGP key?

GPG is an implementation of the PGP (Pretty Good Privacy) specification. It's a common tool used for asymmetric encryption. Asymmetric encryption is basically this:

  1. Bob asks Jill for her public key,
  2. Bob encrypts his message with Jill's public key and gives her the encrypted message, then
  3. Jill decrypts the message with her private key.

The idea is that, when a message is encrypted with a public key, it can only be decrypted by the associated private key. Thus the person who owns the private key is the only one who can read the decrypted message.

## How to send a message

First, write a message! For example, let's save it to message.txt.

You can import a key in many ways, but generally you can copy the link to their public key and run:

curl -s https://example.com/jill.pgp | gpg --import

After importing their key, you can use it to encrypt messages by specifying their email.

gpg --encrypt --armor --recipient jill@example.com < message.txt
# Or, for short:
gpg -ea -r jill@example.com < message.txt

This should spit out a whole lot of gobbledygook, which you can copy to your clipboard and send it straight to them. Now you can basically have end-to-end encryption in any app!

## How to decrypt a message

Let's say you're Jill now. Before Bob can send his message, you need a public/private keypair.

gpg --full-gen-key

Follow the prompts and give Bob your public key. DON'T SHARE YOUR PRIVATE KEY!!! Otherwise everyone will be able to decrypt your secret messages.

Now you've received Bob's message gobbledygook, save it as a file and decrypt it like so:

gpg --decrypt message.txt
# Or, for short
gpg -d message.txt

And it should print out the contents of Bob's secret message!