How To Send And Receive Encrypted Messages Using Gpg

By admin ·
1

Install GPG

Ubuntu/Debian

sudo apt-get install gnupg

CentOS

sudo yum install gnupg

MacOS

How to Install Homebrew on Mac

brew install gnupg
2

Generate your public and private keys

gpg --gen-key
At this point, Alice should follow this step and generate her key pair as well.
3

Export your public key

gpg --export EMAIL > pubkey.asc
pubkey.ascAlice should follow this step and export her public key as well.
4

Exchange public keys with Alice

Note: When sending your key, it’s important that Alice can trust that the key came from you and likewise, that you can trust that the real Alice received your key. This is a security challenge of it’s own and is outside the scope of this guide. Just be sure to use a communication channel that is trustworthy enough.
5

Import Alice’s public key

gpg --import alicepubkey.asc
At this point, you may want to trust Alice’s public key. To do so use:
gpg --edit-key Alice
Then in the gpg prompt, type:
trust
Then select the level of trust 1-5.
6

Review the keys in your keyring

gpg --list-keys
$ gpg --list-keys

/Users/me/.gnupg/pubring.kbx
-------------------------------
pub   rsa2048 2017-05-03 [SC] [expires: 2019-05-03]
      A43BE404BXE42BF68C3810A329BD7XBDE33C02E9
uid           [ultimate] Tyler <[email protected]>
sub   rsa2048 2017-05-03 [E] [expires: 2019-05-03]

pub   rsa2048 2017-08-01 [SC] [expires: 2019-08-01]
      975B17E6B7A17E4431145375X13E5Y76D6EAEB19
uid           [ultimate] Alice <[email protected]>
sub   rsa2048 2017-08-01 [E] [expires: 2019-08-01]
7

Encrypt the message you want to send

message-for-alice
gpg --encrypt --recipient [email protected] message-for-alice
message-for-alice.gpg
8

Decrypt message you’ve received

gpg --decrypt message-for-me.gpg
gpg --decrypt --output message message-for-me.gpg
9

Sign a message

gpg --output message.sig --sign message-for-alice.gpg
message.sig
10

Verify a signed message

gpg --decrypt --output message.gpg message.sig
gpg: Signature made Tue Nov 21 21:51:45 2017 PST
gpg:                using RSA key A43BE404B2E42BF68C3860A329BD72BDE33C02E9
gpg: Good signature from "Tyler <[email protected]>"
message.gpg
gpg --decrypt --output message message.gpg
11

GPG Frontends