, 1 min read

Using GnuPG for encryption and decryption

On Ubuntu install with:

apt-get install gnupg

First generate private and public key:

gpg --gen-key

Generating this key can take some time, because it needs enough randomness.

Store your public key in a file:

gpg -a --export

Although it is not necessary to store this public key, you usually will provide this public key to other people, see for example my public key.

Import public keys from other people by

gpg --import my-friend.pub

Now encrypt a message for my-friend:

gpg -aesr my-friend your-file

These options have the following effect:

  1. -a: create base64 encoded output ("ASCII armored"). This is not necessary, so you can skip this option. If skipped the output is binary.
  2. -e: encrypt
  3. -s: add signature. This is not necessary. You could drop this option from above.
  4. -r: recipient, here your-friend

Decrypting a file is the easiest part. Just type

gpg encrypted-file