Skip to content

Instantly share code, notes, and snippets.

@morkin1792
Last active June 3, 2026 09:08
Show Gist options
  • Select an option

  • Save morkin1792/48844e913d5348968ca5bb6a22924892 to your computer and use it in GitHub Desktop.

Select an option

Save morkin1792/48844e913d5348968ca5bb6a22924892 to your computer and use it in GitHub Desktop.
gpg quick start

creating gpg key pair

gpg --full-generate-key

exporting public key

gpg --export --armor email@email > key.asc

importing public key

gpg --import pub.asc

listing public keys

gpg --list-public-keys

asymmetric encryption (using a public key)

# or -e        -r
gpg --encrypt --recipient friend@email file
 cat message.txt | gpg --encrypt --recipient email@email | base64 -w0 && echo

symmetric encryption (using a password)

# or -c
gpg --symmetric file
 cat message.txt | gpg --symmetric | base64 -w0 && echo

decrypting

# or -d
gpg --decrypt file.gpg > file
cat secret.txt | base64 -d | gpg -d

backup from a previous homedir

PREVIOUS_HOMEDIR=/previous_home/.gnupg
gpg --homedir $PREVIOUS_HOMEDIR --export --armor > backup.asc
gpg --homedir $PREVIOUS_HOMEDIR --export-options backup --export-secret-keys --armor >> backup.asc

restore to the current homedir

gpg --import backup.asc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment