gpg(1)
Encrypt, decrypt, and sign files or data using the GNU Privacy Guard implementation of OpenPGP.
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
| Flag | What it does |
|---|---|
-c, --symmetric | Encrypt using a symmetric cipher (password-based, no keys needed) |
-e, --encrypt | Encrypt data to one or more recipients; requires recipient key IDs |
-d, --decrypt | Decrypt encrypted data; prompts for passphrase if needed |
-s, --sign | Sign data with your private key to prove authenticity |
-u, --local-user KEY-ID | Use specified key for signing instead of default key |
-r, --recipient KEY-ID | Encrypt to specified recipient; use multiple times for multiple recipients |
--armor | Output ASCII-armored format instead of binary (safer for email/text) |
--output FILE, -o FILE | Write output to FILE instead of stdout |
--list-keys | List all keys in the keyring with their details |
--gen-key | Generate a new key pair interactively |
--batch, --no-interactive | Run in batch mode without interactive prompts (useful for scripts) |
--trust-model always | Assume 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-keyEncrypt secret.txt with a password using symmetric encryption; creates secret.txt.gpg
gpg -c secret.txtDecrypt and display secret.txt.gpg to stdout; prompts for the password you used
gpg -d secret.txt.gpgEncrypt message.txt for Alice using her public key, output as ASCII-armored file
gpg -r [email protected] -e message.txt --armor --output message.gpgSign document.pdf with Bob's key and output ASCII-armored signature
gpg -s -u [email protected] document.pdf --armor --output document.pdf.sigDisplay all keys in your keyring with their key IDs, user names, and validity
gpg --list-keysDownload and import a public key from a keyserver using its key ID
gpg --recv-keys 0x12345678Verify that a detached signature matches the original document; checks authenticity
gpg --verify document.pdf.sig document.pdf