Skip Navigation

28 Apr 2022

PGP keys

Sahil Kokamkar
Unsplash Credit:@alpduran

So today my PGP keys got expired, though why shouldn't write about it?

What are PGP keys?

PGP (Pretty Good Privacy) is an encryption program which is used to do digital signature, encrypting files and text and decrypting.

Generating key pairs

gpg --full-generate-key

It will ask your name, e-mail and a passphrase. And then it will generate a public and private key along with a revocation certificate. Make sure you save your private key and revocation certificate securely and make sure yo don't share it with anyone.

Viewing Key Pairs

gpg --list-keys

Exporting public key

gpg --output ~/mypub.key --armor --export <your email>

PGP Keyserver

They are used for storing and retrieving public key. And keyserver shares the key to a network of keyservers, so your key is not stored in a single keyserver.

Uploading key to keyserver

gpg --send-keys --keyserver <keyserver> <Key-ID>

You can select keyserver of your choice, there any many key servers out there.

For eg:

Searching for key

gpg --keyserver <keyserver> --search-keys <name or email address>

Just make sure you verify the fingerprint with the key owner before use.

How to use it?

Encrypting file

The -r is for recipient you want to encrypt for just enter there email. And -e encrypts it.

gpg -r <email> -e filename

You will get a filename.gpg

Decrypting file

Use the -d tag to decrypt file.

gpg -d filename.gpg

Then you will be promoted to enter you passphrase to decrypt it.

You can also use your PGP with your email client or other apps.