LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

gpg2

GnuPG 2 encryption and digital signatures

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
Import a key
$ gpg2 --import [public.asc]
copy
Symmetric encryption with passphrase
$ gpg2 -c [file]
copy

SYNOPSIS

gpg2 [options] [files]

DESCRIPTION

gpg2 (GnuPG 2) is the modern version of GNU Privacy Guard, implementing the OpenPGP standard for encryption, digital signatures, and key management. It uses a modular architecture with separate daemons for improved security.On most modern systems, gpg is aliased to gpg2. The two share keyrings and are functionally equivalent, with gpg2 offering improved architecture and daemon management.

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
Generate key pair with default settings.
--full-generate-key
Generate key pair with full options (algorithm, size, expiry).
--list-keys
List public keys.
--list-secret-keys
List private keys.
--export keyid
Export public key.
--import file
Import keys.
--delete-keys keyid
Delete public key from keyring.
--delete-secret-keys keyid
Delete secret key from keyring.
--keyserver server
Keyserver to use.
-o, --output file
Write output to file instead of stdout.
--clearsign
Make a cleartext signature.
--detach-sign
Make a detached signature.
-c, --symmetric
Encrypt with a symmetric cipher using a passphrase.
--batch
Run in non-interactive batch mode.
-q, --quiet
Minimize output.
-v, --verbose
Display detailed processing information.

CONFIGURATION

~/.gnupg/gpg.conf

User configuration file for default options, preferred algorithms, and keyserver settings.
~/.gnupg/gpg-agent.conf
Configuration for the gpg-agent daemon handling passphrase caching and key operations.

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), gpgconf(1)

Copied to clipboard
Kai