How To Send And Receive Encrypted Messages Using Gpg
1
Install GPG
Ubuntu/Debian
sudo apt-get install gnupgCentOS
sudo yum install gnupgMacOS
How to Install Homebrew on Mac
brew install gnupg2
Generate your public and private keys
gpg --gen-keyAt this point, Alice should follow this step and generate her key pair as well.3
Export your public key
gpg --export EMAIL > pubkey.ascpubkey.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.ascAt this point, you may want to trust Alice’s public key. To do so use:gpg --edit-key AliceThen in the gpg prompt, type:trustThen 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-alicemessage-for-alice.gpg8
Decrypt message you’ve received
gpg --decrypt message-for-me.gpggpg --decrypt --output message message-for-me.gpg9
Sign a message
gpg --output message.sig --sign message-for-alice.gpgmessage.sig10
Verify a signed message
gpg --decrypt --output message.gpg message.siggpg: Signature made Tue Nov 21 21:51:45 2017 PST
gpg: using RSA key A43BE404B2E42BF68C3860A329BD72BDE33C02E9
gpg: Good signature from "Tyler <[email protected]>"message.gpggpg --decrypt --output message message.gpg11