Catalog / GnuPG (GPG) Cheatsheet
GnuPG (GPG) Cheatsheet
A comprehensive guide to using GnuPG (GPG) for encryption, signing, and key management. This cheatsheet covers essential commands and workflows for securing your communications and data.
Key Management
Generating Keys
Generate a new key pair:
This command starts an interactive process to generate a new key pair. You’ll be prompted for various options like key type, key size, and expiration date. |
Generate a new key pair with dialogs for all options:
Provides more detailed options during key generation, such as selecting the key algorithm and curve. |
Batch Key Generation (without interaction):
Automates key generation, useful for scripting. Replace |
Listing Keys:
These commands display the keys in your keyring. Public keys are used to encrypt messages to you, while secret keys are used to decrypt messages and sign documents. |
Listing Keys with Fingerprints:
Display the fingerprint of a specific key. Very important for verifying key identity with others. |
Exporting and Importing Keys
Exporting Keys:
Exports the key in binary format. |
Exporting Keys in ASCII:
Exports the key in an ASCII armored format, suitable for sharing via text. |
Importing Keys:
Imports keys from a file. |
Importing with Merge-Only Option:
Only updates existing keys in your keyring, ignoring new keys. |
Exporting Secret Key:
Exports the secret key (keep this secure!). Add |
Considerations for Secret Key Export:
|
Key Servers
Importing Keys from a Keyserver:
Downloads keys from a keyserver. |
Uploading Keys to a Keyserver:
Uploads your public key to a keyserver. |
Refreshing Keys from a Keyserver:
Updates keys in your keyring from a keyserver. |
Searching for Keys on a Keyserver:
Searches for keys on a keyserver. |
Specifying a Keyserver:
Overrides the default keyserver. Add to |
Encryption and Decryption
Public Key Encryption
Encrypting a File:
Encrypts |
Specifying Recipient Options:
Use key ID, name, or email to specify the recipient. |
Encrypting for Multiple Recipients:
Encrypts the file so that multiple recipients can decrypt it. |
Important Notes:
|
Symmetric Encryption
Encrypting with a Shared Key:
Encrypts the file using a passphrase, prompting for it during encryption. Anyone with the passphrase can decrypt the file. |
Decryption
Decrypting a File:
Decrypts |
Decrypting to Standard Output:
Prints the decrypted content to standard output (terminal). |
Passphrase Prompt: For symmetric encryption, you’ll be prompted for the passphrase. |
Important Notes:
|
Signing and Verification
Signing Files
Creating a Detached Signature:
Creates a detached signature file ( |
Creating an Integrated Signature:
Creates an integrated signature, resulting in a binary file ( |
Signing and Encrypting:
Signs the file while encrypting it. |
Clearsigning a File:
Creates a human-readable signature embedded within the file (creates |
Verifying Signatures
Verifying a Detached Signature:
Verifies the signature file ( |
Verifying an Integrated Signature:
Verifies an integrated signature. |
Verifying a Clearsigned File:
Verifies a clearsigned file. |
Viewing Content of Signed File:
Decrypts and displays the content of a signed file. |
Advanced Usage and Troubleshooting
Trusting Keys
Trusting a Key Interactively:
In the interactive prompt:
Sets the level of trust you have in a key. This helps GPG decide if signatures from this key are valid. |
Using Email/Name instead of Key ID: You can often use the owner’s email or name (or part thereof) instead of the key ID for |
Trust levels:
|
Managing GPG Components
Listing Components:
Lists all GPG components. |
Killing a Component:
Kills a specific component (e.g., |
Killing All Components:
Kills all running GPG components. |
Restarting GPG Agent:
Restarts the GPG agent, which manages secret keys. |
Parsing Keyring Data
Using Colon-Separated Output:
Produces output that is easily parsed with tools like |
Quick Reference for Fields: Refer to the GnuPG documentation for detailed explanations of each field. Common fields include Record Type, Validity, Key Length, Key ID, Creation Date, and User ID. |
Troubleshooting
“No secret key” error: Ensure the correct secret key is present in your keyring and that the GPG agent is running. |
Signature verification failed: Verify that you have the correct public key for the signer and that the original file hasn’t been altered. |
GPG agent issues: Try restarting the GPG agent using |
Keyserver errors: Try a different keyserver or check your network connection. |