# revocation certificates can be issued if# the private key is lost or compromisedgpg--outputyour-new-certificate-name.asc--gen-revokeyour-key-id
# list keys. helpful for finding the key idgpg--list-keys
# print key to the terminal
gpg --armor --export your-email@your-domain.com your-key-id
# add an existing gpg key to profilegpg--import $HOME/.gnupg/file-name.gpg# sign the imported key# ONLY IF YOU VERIFY THE FINGERPRINT!!!gpg--edit-keysomeone-you-trust@their-domain.com
GPG (technically gpg2) is the OpenPGP part of the GNU Privacy Guard (GnuPG). It ships with your EC2 instance and offers digital encryption and signing services. It also can be used for secure shell applications (GitHub supports GPG keys for SSH).
Technically, the pre-installed package is**gpg2**, which is targeted for desktop use whereas the original gpg package is for server and embedded platforms. Your ec2 instance will interpret both gpg and gpg2 commands as gpg2. This documentation will use the form gpg for simplicity.
Tamper Resistant Digital Signatures
Digital signature certifies and timestamps a document. Any changes to that file, however slight, will be unable to pass the verification process.
Creating and verifying signatures uses the public/private keypair from the SSH and PKI discussion; however, the operation is different from encryption and decryption.
Getting Started
Go ahead and create a new primary key pair so you can get started with gpg.
# inputgpg--gen-key# outputPleaseselectwhatkindofkeyyouwant: (1) RSAandRSA (default) (2) DSAandElgamal (3) DSA (sign only) (4) RSA (sign only)Yourselection?2# 2 generates DSA for signing and Elgamal for encryptingSAkeysmaybebetween1024and3072bitslong.Whatkeysizedoyouwant? (2048) 2048 # default is 2048Requestedkeysizeis2048bitsPleasespecifyhowlongthekeyshouldbevalid.0=keydoesnotexpire<n> =keyexpiresinndays<n>w=keyexpiresinnweeks<n>m=keyexpiresinnmonths<n>y=keyexpiresinnyearsKeyisvalidfor? (0) # zero means no expirationKeydoesnotexpireatallIsthiscorrect? (y/N) yGnuPGneedstoconstructauserIDtoidentifyyourkey.# enter your own information when you get to this screenRealname:KennethShultzEmailaddress:kshultz@permitzip.comComment:GadgetEngineeringDirectorYouselectedthisUSER-ID:"Kenneth Shultz (Gadget Engineering Director) <kshultz@permitzip.com>".........
You will be prompted to create a passphrase for your key pair; proceed to do so, preferably using a memorable phrase with a length of several words.
Take note of your new Key ID in the output (Line 3 below):
# outputgpg:/home/ec2-user/.gnupg/trustdb.gpg:trustdbcreatedgpg:key9FCE5492markedasultimatelytrusted#Key ID = 9FCE5492publicandsecretkeycreatedandsigned.gpg:checkingthetrustdbgpg:3marginal(s) needed,1complete(s) needed,PGPtrustmodelgpg:depth:0valid:1signed:0trust:0-,0q,0n,0m,0f,1upub2048D/9FCE54922022-06-09Keyfingerprint=CD377CB14E4742DCD0C2E0F112C5ED0C224F4A80uidKennethShultz (Gadget EngineeringDirector) <kshultz@permitzip.com>sub2048g/D436E7FC2022-06-09%
Generate Revocation Certificate
With the new key pair created, immediately generate a revocation certificate for the primary public key.
revocation certificates may be published to notify others that the public key has expired (perhaps due to a lost key, etc)
can be used to verify signatures made in the past
cannot be used to encrypt future messages
does not impact the ability to decrypt past messages (if you still have the private key)
Create a revocation certificate using:
# inputgpg--output $HOME/.gnupg/your-new-certificate-name.asc--gen-revokeyour-key-id# example key-id: 9FCE5492 # outputsec2048D/9FCE54922022-06-08KennethShultz (Gadget EngineeringDirector) <kshultz@permitzip.com>Createarevocationcertificateforthiskey? (y/N) y #confirm yesPleaseselectthereasonfortherevocation:0=Noreasonspecified1=Keyhasbeencompromised2=Keyissuperseded3=KeyisnolongerusedQ=Cancel(Probablyyouwanttoselect1here)Yourdecision?0Enteranoptionaldescription; end it with an empty line:>#No description necessary; could enter something like # "safety revocation certificate"Reasonforrevocation:Noreasonspecified(Nodescriptiongiven)Isthisokay? (y/N) yYouneedapassphrasetounlockthesecretkeyforuser:"Kenneth Shultz (Gadget Engineering Director) <kshultz@permitzip.com>"# Use same passphrase from key creation process2048-bitDSAkey,ID9FCE5492,created2022-06-08ASCIIarmoredoutputforced.Revocationcertificatecreated.......
Your revocation certificate has been stored in $HOME/.gnupg/ as your-new-certificate-name.asc (See line 2 above). Check your key ring out now:
You will need to share your key so that others may verify your signatures. Use the command below, but replace the email and key ID (9FCE5492) with your information:
A gpg shell has been spawned (gpg>); proceed to enter the following fpr and sign commands. Before using your passphrase to complete the signing process, verify that the fingerprint (Line 9 below) matches exactly to:
Here we pass kshultz@permitzip.com as the recipient to encrypt the message using Kenny's key. We create and define message.txt.gpg as the output (encrypted file).
You will never be able to decrypt this file without Kenny's private key.
Kenny could now decrypt this message using his private key and resolve it to message.txt with the command: