Skip to content

Instantly share code, notes, and snippets.

@aleksbelic
Last active March 31, 2026 21:38
Show Gist options
  • Select an option

  • Save aleksbelic/c476126d8c477a5de1b96ac005fafa15 to your computer and use it in GitHub Desktop.

Select an option

Save aleksbelic/c476126d8c477a5de1b96ac005fafa15 to your computer and use it in GitHub Desktop.
GPG commands overview
# list all public keys stored in your keyring:
gpg --list-keys
# list all private keys stored in your keyring:
gpg --list-secret-keys
# generate a new key(pair):
gpg --gen-key
# generate a revocation certificate:
use gpg --gen-revoke
# import a public key or a private key, use the --import switch:
gpg --import key.pgp
# export a public key, use the --export switch:
gpg --export KEY_ID
# export a private key, use the --export-secret-keys switch:
gpg --export-secret-keys KEY_ID
# In order to operate in ASCII mode, use the --armor (or -a) switch.
# encrypt a file in GPG, use the --encrypt (or -e) switch. Note: you have to specify the recipient as well so GPG knows which public key to use. To do that, use the --recipient (or -r) switch:
gpg --encrypt --recipient RECIPIENTS_EMAIL FILE_NAME
or
gpg -e -r RECIPIENTS_EMAIL FILE_NAME
# sign files, use the --sign (or -s) switch:
gpg -s FILE_NAME
or to encrypt it as well:
gpg -e -s -r RECIPIENTS_EMAIL FILE_NAME
# decrypt files you can use the --decrypt (or -d) switch, or no switch at all - it’s the default option:
gpg FILE_NAME
or
gpg -d FILE_NAME
# in order to find the fingerprint of a key, use the --fingerprint option.
# verify a file, run the following command in the directory with both files: file you want to verify and the file with the signature:
gpg --verify FILE_NAME FILE.sig
or skip .sig if the signature file is named exactly the same as the target file
gpg --verify FILE_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment