$linuxjunkies
>

gpg(1)

Encrypt, decrypt, and sign files or data using the GNU Privacy Guard implementation of OpenPGP.

UbuntuDebianFedoraArch

Synopsis

gpg [OPTION]... [FILE]...

Description

GPG is a command-line tool for encrypting and decrypting data using public-key cryptography. It implements the OpenPGP standard and is commonly used for securing emails, files, and packages. GPG manages a keyring of public and private keys for encryption, decryption, and digital signatures.

The most common workflows involve encrypting files for recipients (using their public keys), decrypting received messages (using your private key), and signing data to prove authenticity. GPG can operate interactively or in batch mode for automation.

Common options

FlagWhat it does
-c, --symmetricEncrypt using a symmetric cipher (password-based, no keys needed)
-e, --encryptEncrypt data to one or more recipients; requires recipient key IDs
-d, --decryptDecrypt encrypted data; prompts for passphrase if needed
-s, --signSign data with your private key to prove authenticity
-u, --local-user KEY-IDUse specified key for signing instead of default key
-r, --recipient KEY-IDEncrypt to specified recipient; use multiple times for multiple recipients
--armorOutput ASCII-armored format instead of binary (safer for email/text)
--output FILE, -o FILEWrite output to FILE instead of stdout
--list-keysList all keys in the keyring with their details
--gen-keyGenerate a new key pair interactively
--batch, --no-interactiveRun in batch mode without interactive prompts (useful for scripts)
--trust-model alwaysAssume all keys are fully trusted (disables trust warnings)

Examples

Generate a new public/private key pair interactively; follow prompts for name, email, and passphrase

gpg --gen-key

Encrypt secret.txt with a password using symmetric encryption; creates secret.txt.gpg

gpg -c secret.txt

Decrypt and display secret.txt.gpg to stdout; prompts for the password you used

gpg -d secret.txt.gpg

Encrypt message.txt for Alice using her public key, output as ASCII-armored file

gpg -r [email protected] -e message.txt --armor --output message.gpg

Sign document.pdf with Bob's key and output ASCII-armored signature

gpg -s -u [email protected] document.pdf --armor --output document.pdf.sig

Display all keys in your keyring with their key IDs, user names, and validity

gpg --list-keys

Download and import a public key from a keyserver using its key ID

gpg --recv-keys 0x12345678

Verify that a detached signature matches the original document; checks authenticity

gpg --verify document.pdf.sig document.pdf

Related commands