GPG Cheatsheet 🛡️

🔑 Key Management

Generate a new GPG key pair:

gpg --full-generate-key

List all keys in your GPG keyring:

gpg --list-keys

List all the secret keys in your GPG keyring:

gpg --list-secret-keys

🔒 Message Encryption and Decryption

Encrypt a message:

gpg -e -u "your-email@example.com" -r "recipient@example.com" message.txt

Decrypt a message:

gpg -o decrypted-message.txt -d message.txt.gpg

📁 GPG Folder Encryption Cheat Sheet

Encrypting a Folder

  1. Create a tarball from the folder you want to encrypt:
  2. tar -czvf archive.tar.gz /path/to/folder_to_encrypt
  3. Encrypt the tarball using GPG:
  4. gpg -e -r your-email@example.com archive.tar.gz

Decrypting a Folder

  1. Decrypt the GPG file to a tarball:
  2. gpg -o archive.tar.gz -d archive.tar.gz.gpg
  3. Extract the tarball to the original folder:
  4. tar -xzvf archive.tar.gz

✉️ Encrypting a Message for Yourself: [Different Method]

  1. Generate a Key Pair:
  2. gpg --gen-key
  3. Encrypt the Message:
  4. gpg -e -u "Your Name" -r "Your Name" message.txt
  5. Decrypt the Message:
  6. gpg -d message.txt.gpg

👥 Encrypting a Message for Someone Else:

  1. Import Their Public Key:
  2. gpg --import theirkey.gpg
  3. Encrypt the Message:
  4. gpg -e -u "Your Name" -r "Their Name" message.txt

🔄 Exporting & Importing Keys

Exporting Your Public Key:

  1. List your keys to find the one you want to export:
  2. gpg --list-keys
  3. Export it to a file:
  4. gpg --export -a "Your Name" > public.key