Guide to GNU Privacy Guard

../ cheatsheet

This guide will focus on how to use gpg in a terminal only, there are already several easy to use programs and apps with a gui if you want to skip this.

gpg is a command on all unix systems to encrypt and decrypt text files and messages, to sign files and messages for secure communication, limited compression, and managing keys using public key cryptography, aka asymmetric cryptography.

Just to quickly explain how this encryption and decryption works, everyone has a private key and public key. You can share your public key to anybody and they use that key to encrypt a message or file for you. When you receive that message you then decrypt it with your private key. Trying to crack the private key is practically impossible with modern computers. Due to the threat quantum computers pose on the current encryption algorithms, post quantum encryption algorithms are already being created and experimented with.

Starting

Check if you have gpg installed by running this command in your terminal. If you don’t have it, install it with your package manner.

gpg --version

Now create a key

gpg --full-gen-key

Please select what kind of key you want. You’ll have options of what algorithm to use. Ignore any kind that says ‘only’ and stick with ECC. RSA has larger results and is slower but is still perfectly compatible. Select the default curve listed.

Please specify how long the key should be valid. The expiration of your key can be changed later if needed.

Real name. You can put your name or alias, make it unique because others may have to use this to encrypt for you.

Email address. Optional, but if you have a common name people may use this to encrypt for you.

Comment. Optional as well.

Exporting Public Key

Check if your key exists

gpg --list-keys

To see your public key run this, replace name with what you wrote.

gpg --export <name>

If you want that key in ASCII format, add the -a

gpg --export -a <name>

If want to copy and paste it, include the 5 hyphens at the very start and the very end.

You can also direct it straight into a file. While choosing a file format is not necessary, it can still be helpful to others.

gpg --export name > key.gpg

gpg --export -a name > key.asc

And check that file before sharing.

gpg --show-keys key.*

Importing Public Key

If you have someone’s public key in your clipboard ready run

gpg --import

and then paste it in that standard input, enter a new line, and CTRL+d to get it imported.

Check that it was successfully imported

gpg --list-keys

If you have a file ready run

gpg --import <file>

This also accepts pipes

curl https://davidvoz.net/dv.asc | gpg --import

echo "-----BEGIN PGP... BLOCK-----" | gpg --import

Encryption

Decryption

Signing

Verifying

Compressing

Cheat Sheet