LinuxCommandLibrary

gpg2

TLDR

Generate key pair

$ gpg2 --full-generate-key
copy
List keys
$ gpg2 --list-keys
copy
Encrypt file for recipient
$ gpg2 -e -r [recipient@email.com] [file]
copy
Decrypt file
$ gpg2 -d [file.gpg]
copy
Sign file
$ gpg2 --sign [file]
copy
Verify signature
$ gpg2 --verify [file.sig]
copy
Export public key
$ gpg2 --armor --export [keyid] > [public.asc]
copy

SYNOPSIS

gpg2 [options] [files]

DESCRIPTION

gpg2 (GnuPG 2) is the GNU Privacy Guard, an implementation of the OpenPGP standard. It provides encryption, digital signatures, and key management for secure communication.
gpg2 is the modern version with improved architecture, splitting functionality into separate daemons. Most systems alias gpg to gpg2.

PARAMETERS

-e, --encrypt

Encrypt data.
-d, --decrypt
Decrypt data.
-s, --sign
Sign data.
--verify
Verify signature.
-r, --recipient name
Encrypt for recipient.
-a, --armor
ASCII armored output.
--gen-key, --full-generate-key
Generate key pair.
--list-keys
List public keys.
--list-secret-keys
List private keys.
--export keyid
Export public key.
--import file
Import keys.
--keyserver server
Keyserver to use.

CAVEATS

Key management requires understanding of web of trust. Private keys must be protected. Passphrase selection is critical. gpg and gpg2 share keyrings on modern systems.

HISTORY

GnuPG was created by Werner Koch in 1997 as a free replacement for PGP. GPG 2.0 was released in 2006 with a modular architecture. It's a fundamental tool for secure email and software signing.

SEE ALSO

gpg(1), gpg-agent(1), gpgconf(1)

Copied to clipboard