Skip to content

GnuPG

16 commands

The free implementation of OpenPGP: generate keys, encrypt and decrypt files, and create and verify digital signatures — used everywhere from email to release verification.

  • encryption
  • PGP
  • signing
  • keys

Install GnuPG

sudo apt install gnupg

Keys5

gpg --full-generate-key

Interactively creates a new key pair; choose RSA 4096 or an ECC curve.

gpg --list-keys

Lists public keys in your keyring; --list-secret-keys shows private keys.

gpg --export -a <id> > <file>

Exports a public key in ASCII-armored form.

Link
gpg --import <file>

Imports a key into your keyring.

Link
gpg --fingerprint <id>

Shows a key’s fingerprint to verify it out of band.

Link

Encrypting4

gpg -e -r <recipient> <file>

Encrypts a file to a recipient’s public key, producing file.gpg.

Link
gpg -e -r <a> -r <b> <file>

Encrypts so several recipients can each decrypt.

Link
gpg -c <file>

Symmetric encryption with a passphrase — no keys needed.

Link
gpg -d <file>.gpg > <out>

Decrypts a file.

Link

Signing & verifying4

gpg --sign <file>

Creates a signed, compressed version of a file.

Link
gpg --detach-sign -a <file>

Creates a separate .asc signature, the usual way to sign releases.

Link
gpg --verify <sig> <file>

Verifies a detached signature against the file.

Link
gpg --verify <file>.asc

Verifies a clearsigned or inline-signed file.

Link

Maintenance3

gpg --edit-key <id>

Opens the key editor to set trust, add user IDs or expiry.

Link
gpg --export-secret-keys -a <id> > <file>

Backs up a private key — store it somewhere safe.

Link
gpg --armor --export <id> | gpg --keyserver <ks> --send-keys <id>

Publishes a public key to a keyserver.

Link