From 2c44c8494fdacf9ece6398963980bf8535419aba Mon Sep 17 00:00:00 2001 From: "$./Netrunner_&" <114373528+00xNetrunner@users.noreply.github.com> Date: Sun, 15 Oct 2023 22:21:26 +0100 Subject: [PATCH] Update GPG_Cheatsheet.md --- GPG_Cheatsheet.md | 196 +++++++++++++++++++--------------------------- 1 file changed, 81 insertions(+), 115 deletions(-) diff --git a/GPG_Cheatsheet.md b/GPG_Cheatsheet.md index d684594..7722ced 100644 --- a/GPG_Cheatsheet.md +++ b/GPG_Cheatsheet.md @@ -1,143 +1,109 @@ + + + + GPG Cheatsheet 🛡️ + + + -## GPG cheatsheet +

GPG Cheatsheet 🛡️

-### Key Management +

🔑 Key Management

-- **Generate a new GPG key pair:** +

Generate a new GPG key pair:

+gpg --full-generate-key -\`\`\`bash -gpg --full-generate-key -\`\`\` +

List all keys in your GPG keyring:

+gpg --list-keys -- **List all keys in your GPG keyring:** +

List all the secret keys in your GPG keyring:

+gpg --list-secret-keys -\`\`\`bash -gpg --list-keys -\`\`\` +

🔒 Message Encryption and Decryption

-- **List all the secret keys in your GPG keyring:** +

Encrypt a message:

+gpg -e -u "your-email@example.com" -r "recipient@example.com" message.txt -\`\`\`bash -gpg --list-secret-keys -\`\`\` +

Decrypt a message:

+gpg -o decrypted-message.txt -d message.txt.gpg -# Message Encryption and Decryption +

📁 GPG Folder Encryption Cheat Sheet

-- **Encrypt a message:** +

Encrypting a Folder

-\`\`\`bash -gpg -e -u "your-email@example.com" -r "recipient@example.com" message.txt -This creates message.txt.gpg. -\`\`\` +
    +
  1. Create a tarball from the folder you want to encrypt:
  2. + tar -czvf archive.tar.gz /path/to/folder_to_encrypt -- **Decrypt a message:** +
  3. Encrypt the tarball using GPG:
  4. + gpg -e -r your-email@example.com archive.tar.gz +
-\`\`\`bash -gpg -o decrypted-message.txt -d message.txt.gpg -\`\`\` +

Decrypting a Folder

-- This creates `decrypted-message.txt`. +
    +
  1. Decrypt the GPG file to a tarball:
  2. + gpg -o archive.tar.gz -d archive.tar.gz.gpg -# GPG Folder Encryption Cheat Sheet +
  3. Extract the tarball to the original folder:
  4. + tar -xzvf archive.tar.gz +
-## Encrypting a Folder +

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

+ -1. **Create a tarball from the folder you want to encrypt:** +

Encrypting a message for yourself:

- Replace **`/path/to/folder_to_encrypt`** with the path to your folder and **`archive.tar.gz`** with the desired name for your tarball. +
    +
  1. Generate a Key Pair:
  2. + gpg --gen-key - \`\`\`bash - tar -czvf archive.tar.gz /path/to/folder_to_encrypt - \`\`\` +
  3. Encrypt the Message:
  4. + gpg -e -u "Your Name" -r "Your Name" message.txt -2. **Encrypt the tarball using GPG:** +
  5. Decrypt the Message:
  6. + gpg -d message.txt.gpg +
- Replace **`your-email@example.com`** with your email and **`archive.tar.gz`** with your tarball's name. This will create an encrypted file named **`archive.tar.gz.gpg`**. +

👥 Encrypting a Message for Someone Else:

- \`\`\`bash - gpg -e -r your-email@example.com archive.tar.gz - \`\`\` +
    +
  1. Import Their Public Key:
  2. + gpg --import theirkey.gpg -## Decrypting a Folder +
  3. Encrypt the Message:
  4. + gpg -e -u "Your Name" -r "Their Name" message.txt +
-1. **Decrypt the GPG file to a tarball:** +

🔄 Exporting & Importing Keys

- This will decrypt the **`archive.tar.gz.gpg`** file back to **`archive.tar.gz`**. +

Exporting Your Public Key:

- \`\`\`bash - gpg -o archive.tar.gz -d archive.tar.gz.gpg - \`\`\` +
    +
  1. List your keys to find the one you want to export:
  2. + gpg --list-keys -2. **Extract the tarball to the original folder:** +
  3. Export it to a file:
  4. + gpg --export -a "Your Name" > public.key +
- This will extract the contents of the tarball to the current directory. - - \`\`\`bash - tar -xzvf archive.tar.gz - \`\`\` - -Please note that the person performing the decryption and extraction will need the GPG private key that corresponds to the public key used to encrypt the file. - -# Encrypting a message for yourself: [Different Method] - -1. **Generate a Key Pair**: If you haven't already, you'll need to generate a GPG key pair. You can do this with the **`-gen-key`** option: - - \`\`\`bash - gpg --gen-key - \`\`\` - - Follow the prompts to set your name, email address, and passphrase. - -2. **Encrypt the Message**: You can now encrypt a message with your public key. For example, to encrypt a message in a file named **`message.txt`**, you can use the following command: - - \`\`\`bash - gpg -e -u "Your Name" -r "Your Name" message.txt - \`\`\` - - Replace "Your Name" with the name you used when generating your key pair. This will create an encrypted file named **`message.txt.gpg`**. - -3. **Decrypt the Message**: To decrypt the message, you can use the **`gpg`** command with the **`d`** option: - - \`\`\`bash - gpg -d message.txt.gpg - \`\`\` - - You'll be asked for the passphrase you used when generating your key pair. - -# Encrypting a message for someone else: - -1. **Import Their Public Key**: Before you can encrypt a message for someone else, you'll need their GPG public key. Once you have it, you can import it with the **`-import`** option: - - \`\`\`bash - gpg --import theirkey.gpg - \`\`\` - - Replace "theirkey.gpg" with the filename of their public key. - -2. **Encrypt the Message**: You can now encrypt a message with their public key. For example, to encrypt a message in a file named **`message.txt`**, you can use the following command: - - \`\`\`bash - gpg -e -u "Your Name" -r "Their Name" message.txt - \`\`\` - - Replace "Your Name" with your name and "Their Name" with the name associated with their public key. This will create an encrypted file named **`message.txt.gpg`**. - -The recipient will then be able to decrypt the message using their private key. - -# Exporting & Importing Keys - -**Exporting Your Public Key:** - -1. List your keys to find the one you want to export: - - \`\`\`bash - gpg --list-keys - \`\`\` - -2. Once you've identified the key you want to export (it's usually your email address or name), use the **`-export`** option with the **`a`** (armor) flag to export it to a file: - - \`\`\`bash - gpg --export -a "Your Name" > public.key - \`\`\` - - Replace "Your Name" with the name or email associated with the key you want to export. This will create a file named **`public.key`** containing your public key. + +