Skip to content

Instantly share code, notes, and snippets.

@ASteinheiser
Last active June 17, 2023 23:38
Show Gist options
  • Save ASteinheiser/89651bf012267a95d4059a77daf862ff to your computer and use it in GitHub Desktop.
Save ASteinheiser/89651bf012267a95d4059a77daf862ff to your computer and use it in GitHub Desktop.
Commands for basic GPG key message encryption

GPG message encryption basics

Abbreviated flags:

  • -a is --armor for ascii armored output (allows output to be sent via the web, etc.)
  • -r is --recipient for specifying the recipient of the message (needs to use the name of an imported key)

Import a new public GPG key

This can be used for encrypting messages so only the person with the private key can read them

gpg --import ./path/to/public.key

See your GPG keys

You'll need to know the name of the key you want to use

gpg --list-keys

Encrypt a message

This uses the name of the public key that was imported to encrypt the message

gpg --output ./path/to/encrypted.txt --encrypt -a -r NAME_OF_KEY ./path/to/input.txt

Decrypt a message

To decrypt an encrypted message you will need to have the private key associated with the public key that the message was signed with

gpg --output ./path/to/output.txt --decrypt ./path/to/encrypted.txt

Export your public GPG key

If you give this to people then they can encrypt messages that only you can read with your private key

WARNING: Never share your private key

gpg --output ./path/to/public.key --export -a NAME_OF_KEY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment