Skip to content

GnuPG (gpg) cheatsheet

Viktor Ageyev edited this page Mar 31, 2019 · 10 revisions

GnuPG is a free and open sourced implementations of OpenPGP standard.

If you have a UNIX system (macOS or Linux) you probably already have gpg (or gpg2) command available in command line (console).

For Windows see: or/and Practical Introduction to GNU Privacy Guard in Windows by Brendan Kidwell

Check if you have gpg (GnuPG) installed in your system:

gpg --version

Generate a key:

gpg --gen-key

by default keys are stored in folder (directory): ${HOME}/.gnupg/

List (show) keys:

gpg --list-public-keys
gpg --list-secret-keys

Export a public key to file:

gpg -ao publickey.asc --export user@host.com

options:

user@host.com : your email address (replace with actual email used in your key certificate)

--armor or -a : Create ASCII armored output. The default is to create the binary

--output or -o + file name (here: 'publickey.asc') : Write output to file. To write to stdout use - as the filename.

Import pulbic key:

gpg --import publickey.asc

Sign text from text file

gpg --clear-sign somefile.txt

gpg will create a new file (like 'somefile.txt.asc') where signed text will be placed.

Verify signature:

gpg --verify somefile.txt.asc