How-to setup GPG-2 (GnuPG implementation of OpenPGP) https://gnupg.org/
Go to file
Netflix 217c924903 Update 'README.md' 2021-03-05 18:57:16 +01:00
README.md Update 'README.md' 2021-03-05 18:57:16 +01:00

README.md

GPG2-Guide

Installing GPG2

sudo apt-get install gnupg2 -y

Importing into Key Ring

In order for you to send the message to the receiver, you have to import their public key into your king ring.

echo "PUBLIC_KEY_TO_IMPORT" | gpg2 --import

The command above is a easy way for you to import the receiver's public key into your keyring without creating a file.

Replace 'PUBLIC_KEY_TO_IMPORT' with the Public key you want to import. This command will only work on Linux systems.

 gpg2 --import PUBLIC_KEY_TO_IMPORT.txt

The command above is another way of importing a users public key. But this command you have to save their public key in the file, PUBLIC_KEY_TO_IMPORT.txt. This will work on Windows and Linux.

Encrypting message

After you got their public key in your king ring, you can send encrypted messages to the person. Only the person with the private key and the password will be able to read the message. If the site get hacked, or you need to send a message to someone that contains senstive information, anyone that doesnt have the private key and pass will not be able read the information.

echo "Hi, I would like to buy a foot long sub" | gpg2 -ear test123

In the command above, the message that we will be encrypting is Hi, I would like to buy a foot long sub.

  • The 'e' in 'ear' stands for encrypt
  • The 'a' in 'ear' stands for armor. You have to do this to make the output ascii.
  • The 'r' in 'ear' stands for recipient. This has to be the uid of the person you want to send the message to. Usually its a username or sometimes even a email.

Decrypting a message

echo "PGP_ENCRYPTED_MESSAGE" | gpg2 -d 

Making life easier with .bashrc

Remebering and having to type all that just to import a PGP file can be a hassle. If you are on a Linux system, then you can edit your .bashrc file. This file should be stored in your home directory. We are going to add a bash function to the .bashrc file that will make it super easy to import keys to your king ring without having to create a file.

function import_gpg {
        out=$(echo "$1"  | gpg2 --import)
}

In the bash code above. We create a function named import_gpg. This is the new command we created on our system. Inside the function is the same command that we showed you earlier. The $1 variable is the user's input.

After you save the file, you have to run the following command. This command tells your system to reload your bashrc file.

source .bashrc

Now, if we wanted to import a public key into your key ring we could use the following command.

import_gpg "PUBLIC KEY"

Listing keys in your ring

The following command could be used to list all the keys in your keyring.

gpg2 --list-keys

Listing keys and fingerprints

Fingerprints are used to identify a user public key. It is a shorter hash that represents the public key. To list all the fingerprints and keys in your keyring the following command can be used.

gpg2 --fingerprint

You could also use grep with the command. This will allow you to search for certain usernames. Instead of giving you all the keys in your keyring this will only give you results that matches that patterned. Below is an example of the command that could be used.

gpg2 --fingerprint | grep "Mr. Nakatomi"

The | allows you chain the gpg2 command with grep so that grep can take the results of the output from the GPG2 command and use it to search for a username in keyring that matches Mr. Nakatomi