PGPractice

What is GnuPG?

GnuPG (GNU Privacy Guard) is a free implementation of the OpenPGP standard that allows you to encrypt and sign your data and communications. It's a powerful command-line tool used for:

  • Encryption: Protect sensitive information so only intended recipients can read it
  • Digital signatures: Verify the authenticity and integrity of messages and files
  • Key management: Create, import, export, and manage cryptographic keys
  • Secure communication: Enable private communication over insecure channels

Installing GnuPG

macOS

brew install gnupg

Ubuntu/Debian

sudo apt install gnupg

Windows

choco install gnupg

Verify installation by running gpg --version in your terminal.

What You'll Learn

This interactive tutorial will teach you essential GnuPG commands through hands-on practice:

  • Generate secure PGP key pairs
  • Export and share public keys
  • Encrypt messages for specific recipients
  • Decrypt received messages
  • Create and verify digital signatures

Each step includes detailed instructions, example outputs, and real-time validation of your work.

Interactive PGP/GnuPG Command Line Tutorial

Generate Your PGP Key Pair

First, we need to create a PGP key pair using GnuPG. We'll use the full key generation command for more control over options.

Command to run:

gpg --full-gen-key

Step-by-step guide:

1. Key type selection:
Choose 1 for "RSA and RSA" (most compatible)
2. Key size:
Enter 4096 for maximum security (when prompted)
3. Expiration:
Enter 0 for no expiration (for practice purposes)
Confirm with y
4. User ID information:
Real name: Your preferred name
Email: Optionally, your email address
Comment: Optionally, a note explaining what the key is for
Confirm with o for "Okay"
5. Passphrase:
Choose a secure passphrase when prompted (you'll need this later!)

Paste the command output here:

After key generation, verify it was created:

gpg --list-keys

The output should look something like this:

/home/username/.gnupg/pubring.kbx
---------------------------------
pub rsa4096 2024-01-01 [SC]
ABCD1234EFGH5678IJKL9012MNOP3456QRST7890
uid [ultimate] PGPractice (This is a test key for the PGPractice tutorial!) <hello@pgpractice.com>
sub rsa4096 2024-01-01 [E]

Export Your Public Key

Now let's export your public key so others can use it to encrypt messages to you and verify your signatures.

Command to run:

gpg --armor --export your-email@example.com

Replace "your-email@example.com" with the email address you used when creating your key. The --armor flag outputs the key in ASCII format instead of binary.

Paste your public key here:

Encrypt a Message

Now let's encrypt a message using your public key. First, create a simple text file with a message.

Commands to run:

echo "This is a secret message" > message.txt
gpg --armor --encrypt --recipient your-email@example.com message.txt

This creates an encrypted file called message.txt.asc. Display it with: cat message.txt.asc

Paste the encrypted message here:

Decrypt a Message

Now let's decrypt the message you encrypted in the previous step using your private key.

Command to run:

gpg --decrypt message.txt.asc

You'll be prompted to enter your passphrase. GPG will then decrypt and display the original message.

Paste the decryption output here:

Encrypt with Tutorial Key

Now let's test encryption with a key provided by PGPractice. I'll give you a public key, and you encrypt a message with it.

PGPractice Public Key:

Commands to run:

1. Save the PGPractice key above to a file: pgpractice-key.asc
2. Import it: gpg --import pgpractice-key.asc
3. Create your message: echo "Your secret message here" > my-message.txt
4. Encrypt: gpg --armor --encrypt --recipient tutorial@pgpractice.local my-message.txt

Write any message you want! PGPractice will decrypt it and show you what you wrote to confirm encryption worked.

Paste your encrypted message here:

Sign and Verify Messages

Now let's learn to create digital signatures and verify them. This proves authenticity and integrity.

Step 1: Sign a Message

Commands to run:
echo "This message is from me" > signed-message.txt
gpg --clearsign signed-message.txt
Paste the signed message here:

Step 2: Verify the Signature

Command to run:
gpg --verify signed-message.txt.asc
Paste the verification output here: