Table of Contents

Linux Commands Cheat Sheet

gpg : How to use gpg command in Linux with examples



man gpg

NAME
       gpg2 - OpenPGP encryption and signing tool

SYNOPSIS
       gpg2 [--homedir dir] [--options file] [options] command [args]

DESCRIPTION
       gpg2  is  the  OpenPGP part of the GNU Privacy Guard (GnuPG). 
       It is a tool to provide digital encryption and signing services using the OpenPGP standard.

COMMANDS
       --help

       -h     Print a usage message summarizing the most useful command line options. 
gpg --gen-key generate a new key pair
gpg --list-keys list keys
gpg --list-secret-keys list secret keys
gpg --delete-key test@example.com remove keys from the public keyring
gpg --delete-secret-key test@example.com remove keys from the secret keyring
gpg --delete-secret-and-public-key KeyID
gpg --fingerprint list keys and fingerprints
gpg --sign-key somebody@example.com sign a key

Encrypt or Decrypt

gpg -e -r USER-ID FILE -e : encrypt data
-r USER-ID : encrypt for USER-ID
gpg FILE.gpg
gpg -d FILE.gpg
-d : decrypt data (default)

Import and Export Keys

gpg -a --export > FILE.asc
gpg -a --export test@example.com > FILE.asc
--export : export keys
-a : create ascii armored output
gpg -o FILE.key --export test@example.com --export : export keys
-o : write output to FILE (BINARY)
gpg -a --export-secret-key test@example.com > FILE.asc -a : create ascii armored output
gpg -o private.key --export-secret-key test@example.com -o : write output to FILE (BINARY)
gpg --import PublicKEY
gpg --import SecretKEY
import/merge keys