Key Management - Common Tasks

Create your own asymmetric key

sudo apt install gnupg2         # install GnuPG (GPG)
gpg2 --gen-key                  # create public-private key pair

• What kind of key you want? Choose RSA and RSA (default).
• What keysize you want? Choose 2048. (If you have a need for extreme security, you can choose 4096.)
• For how long should the key be valid? Choose 0 = key does not expire


Share your public key

# export public key as a file
gpg2 --armor --export > sarah.asc
cat sarah.asc                   # check content

◇ If you want someone to reply with an encrypted message, send this file (public key) to contacts


Import someone else's public key

gpg2 --import john.asc


View list of keys

gpg2 -k                         # public keys
gpg2 -K                         # private keys


Using public key's fingerprint

gpg2 --fingerprint [names]      # list of fingerprints


Encrypt a file (message)

• Create a text file and save it. Run the following command

gpg2 --armor --encrypt --recipient message.txt

• File message.txt now saved in a new file called message.txt.asc, encrypted, and addressed to recipient using his or her public key
• Attach the file to an email addressed to the recipient


Decrypt a file (message)

gpg2 --decrypt message.txt.asc > message.txt

• You will be prompted to enter the password


APT-Key Add Public Key

sudo apt-key add oracle_vbox_2016.asc