GPG Usage Scenarios

Setup

Generate New Key

gpg --full-generate-key

launches terminal based wizard, so no explanation required.

Export Public Key

To give it to others. First, list the keys to see which one to export with gpg -k:

image-20220308103806600

gpg --export --armor "Aldrich Kemp (test key) <aldrich@kemp.com>"

Import Someone Else’s Public Key

Save the key to someone.gpg file and then:

gpg --import someone.gpg

Encrypt

Encrypt Text “secret text”

echo "secret text" | gpg --encrypt --armor -r recipient@email.com

outputs something like:

-----BEGIN PGP MESSAGE-----

hQGMA49Zy8B1S5WyAQv/TqyRIRaPsyVyEg77eEnp8GuVhEF+1ONh703kYoBi/cvK
fDbgOjMK657m0f4litt8XitlWIKnw3Nzbz/DNMSXRrG0IeCIFFz4MHIKQBHDMyDk
CO6wvk9DTHH8nfMz/anVuk5lQzgB0znmwMlPLU9VxJ4JcMylulSXVWSu9a7c5XB6
OUCzZZAncBE7mgWpIUd5h9ZCyyZgVemr34I6T3UgV8+guEjVQI6GODuaA6QTlCb1
QcDNA76hdJhbuz9GKWfw9N/Bs6BjMK/Y2X5Ds1Uys7riQsjZhGr9pxwgkXatD2Zx
XXndzY1RHZEh9Ifsm/VbrRaFnLGO21e00I7i3zVczCNPd4sQEo53knTauqP+SB2C
3rysgUVKWQq1g9iIcLzwtbcEA19N9y9Ot/38M2ZX0sXwzgmjDCvmB4uWV8puvWSc
dnbsAAhHhxcbfjP1SLXNl1A3TBOcehLtJsLUp2qsV41qRBDzoZaR4BxJi7CjUtws
i8yxUz0exlCCApmK55mL0kcBG2YbazQMPRhD5z3486VWwubWk1n2acU4EtskJHxd
pG3LCCIVjQgmGMwdyCLqLjMDjCC3+27HWj2uV2VeFO4jILxbb+G76g==
=zL1w
-----END PGP MESSAGE-----

Encrypt File “message.txt”

gpg --encrypt -r recipient@email.com message.txt

creates message.txt.gpg in the same folder you can send to the recipient.

Decrypt

Decrypt File “message.txt.gpg”

gpg --decrypt message.txt.gpg > m.txt

puts decrypted content to m.txt.

Thanks! You can always email me or use contact form for more questions/comments etc.