Skip to content

Instantly share code, notes, and snippets.

@edwardstock
Last active April 2, 2024 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardstock/97211526b162cf5b95fb47c3d25ed9e8 to your computer and use it in GitHub Desktop.
Save edwardstock/97211526b162cf5b95fb47c3d25ed9e8 to your computer and use it in GitHub Desktop.
GPG Simple Usage Guide

Define config for quick generation

gpg --default-new-key-algo "ed25519/cert,sign+cv25519/encr" --quick-generate-key "my@email.com"

Generate key

gpg --gen-key

  • Set realname: Name Surname
  • Set eamil: mail@mailbox.up
  • Set strong password

List keys

gpg --list-keys

Remove key from keyring

First, you need to delete secret key, than public

gpg --delete-secret-keys {PUBLIC_KEY}
gpg --delete-keys {PUBLIC_KEY}

Export keys to file

gpg --output /path/to/keys/public.pgp --armor --export {PUBLIC_KEY}
gpg --output /path/to/keys/private.pgp --armor --export-secret-key {PUBLIC_KEY}

Backup keys

gpg --output backupkeys.pgp --armor --export-secret-keys --export-options export-backup
This will export all necessary information to restore the secrets keys including the trust database information. Make sure you store any backup secret keys off the computing platform and in a secure physical location.

Import keys

gpg --import private.gpg
As public key generated from private, you don't need to import public.gpg

Sign file

gpg -s myfile.txt

Encrypt file

gpg -e myfile.txt\

  • Enter your public key or email OR recipient (friend, college or otherwise) public key. If you want to encrypt file to your friend by email, you should add them public keys to your keyring gpg --import friend_public.gpg
  • Enter empty line
  • Done

Encrypt to custom file:
gpg --output mysecretfile.txt -e myfile.txt

Decrypt file

To read contents:
gpg -d myfile.txt.gpg
To decrypt to file
gpg --output myfile.txt -d myfile.txt.gpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment