GPG, short for GNU Privacy Guard and also written GnuPG, is a free implementation of the OpenPGP standard that encrypts data, creates digital signatures and verifies them using public-key cryptography. In cybersecurity, it is the most widely deployed tool for signing software releases, protecting email and files, and proving that a package or commit really comes from its claimed author.
GPG combines asymmetric encryption for key handling with symmetric encryption for bulk data, and it organizes trust through keyrings rather than a central certificate authority. It runs as a command-line program, a library backend and an agent that guards private keys, so it appears inside package managers, version control systems and mail clients that many users never associate with it.
How GPG encrypts and signs data
GPG uses hybrid encryption: it generates a random session key, encrypts the message with a fast symmetric cipher such as AES-256, and then encrypts only that session key with each recipient’s public key. This design keeps large files fast to process while still allowing several recipients to read the same ciphertext with their own private keys.
For a digital signature, GPG computes a hash of the data, typically with SHA-256 or SHA-512, and signs that digest with the signer’s private key. Anyone holding the matching public key can verify that the data is unchanged and that the signature was made by the key holder. Signing and encrypting are independent operations and can be combined in a single pass.
The table below lists the core operations and what each one guarantees.
| Operation | Typical command | What it guarantees |
|---|---|---|
| Public-key encryption | gpg --encrypt -r alice | Confidentiality for named recipients |
| Symmetric encryption | gpg --symmetric | Confidentiality with a passphrase only |
| Detached signature | gpg --detach-sign | Integrity and origin, file left untouched |
| Clear-signed text | gpg --clearsign | Readable text with an embedded signature |
| Verification | gpg --verify | Checks signature against a public key |
Keys, subkeys and algorithms in GPG
A GPG identity is a primary key bound to one or more user IDs (a name and email address) plus a set of subkeys. Each key carries capability flags: certify (C), sign (S), encrypt (E) and authenticate (A). Good practice keeps the primary key for certification only, ideally offline, and uses separate subkeys for daily signing and encryption so a compromised laptop does not destroy the whole identity.
Modern GnuPG versions default to elliptic curve cryptography with Curve25519, using Ed25519 for signatures and Cv25519 for encryption. RSA remains supported and is still common for compatibility with older systems and hardware tokens.
| Algorithm | Typical use | Notes |
|---|---|---|
| Ed25519 | Signing and certification | Short keys, fast, current default |
| Cv25519 | Encryption subkeys | Pairs with Ed25519 identities |
| RSA 3072 or 4096 | Signing and encryption | Broad compatibility, larger keys |
| NIST P-256 or P-384 | Signing and encryption | Used where NIST curves are mandated |
| DSA and ElGamal | Legacy keys only | Avoid for new keys |
Every key has a fingerprint, a hash of the public key material, and a key expiration date. Setting an expiration of one to three years and extending it as needed limits the damage of a lost key, while a pre-generated revocation certificate lets the owner announce that a key must no longer be trusted.
The web of trust and key validation
GPG decides whether a public key truly belongs to its claimed owner through the web of trust, a decentralized model in which users certify each other’s keys after checking fingerprints. Instead of relying on a single authority, a key becomes valid when enough trusted people have signed it, according to the local owner trust settings.
In practice, many organizations replace the classic web of trust with simpler models: trust on first use, keys published on a corporate domain through Web Key Directory (WKD), or fingerprints pinned in documentation and build scripts. The decisive step in every model is the same: compare the full fingerprint through an independent channel before trusting a key.
The comparison below places GPG next to related approaches to key distribution and protection.
| Approach | Trust model | Typical scope |
|---|---|---|
| GPG with OpenPGP | Web of trust or pinned keys | Files, email, software releases |
| S/MIME with X.509 | Certificate authorities | Corporate email |
| SSH signing keys | Allowed signers file | Git commits and tags |
| Sigstore | Short-lived certificates and logs | Container and package signing |
| Signal protocol | Safety numbers per contact | End-to-end encryption in messaging |
Where GPG is used in practice
The most important use of GPG today is software supply chain integrity. Linux distributions sign their package repositories with GPG keys, and package managers such as APT, DNF and RPM refuse unsigned or wrongly signed packages. Open-source projects publish detached signatures next to release archives so users can verify downloads independently of the mirror that served them.
Developers use GPG to produce signed Git commits and tags, which hosting platforms display as verified. Administrators use it to encrypt backups, configuration secrets and data transfers, and tools such as pass or SOPS rely on GPG as an encryption backend. Email encryption with OpenPGP still exists but has become a niche use, because key exchange and metadata exposure make it hard for nonspecialists.
- Repository signing: distribution maintainers sign package metadata, and clients pin the distribution key.
- Release verification: users check a tarball against its
.ascsignature before installation. - Encrypted backups: archives are encrypted to an offline recovery key before upload to cloud storage.
- Hardware tokens: smart cards and security keys hold subkeys so private material never touches disk.
Limitations and common mistakes with GPG
GPG offers strong cryptography but has a reputation for poor usability, and most real failures come from operational errors rather than broken algorithms. OpenPGP does not provide forward secrecy, so a stolen private key can decrypt every past message encrypted to it. Encrypted email also leaves subject lines and metadata visible unless the client protects them separately.
The following table connects frequent mistakes with their consequences and corrections.
| Mistake | Consequence | Correction |
|---|---|---|
| Trusting a short key ID | Collisions allow spoofed keys | Compare the full fingerprint |
| No revocation certificate | Lost key cannot be retired | Generate one at key creation |
| Primary key on daily laptop | Theft compromises the identity | Keep it offline, use subkeys |
| Ignoring verification output | Bad signatures go unnoticed | Check exit codes in scripts |
| Never-expiring keys | Abandoned keys stay valid | Set and renew expiration dates |
Past vulnerabilities such as EFAIL affected mail clients that processed decrypted content unsafely rather than the GPG cryptography itself, which shows that the integration layer is often the weakest point. Keeping GnuPG updated and enforcing integrity protection on encrypted messages remain basic requirements.
Stripped to the essentials
GPG is a free tool that lets people lock files and messages and sign them like a wax seal. Each person has two keys: a public key they can give to anyone and a private key they keep secret. Anyone can use the public key to lock something for that person, but only the private key opens it.
Signing works the other way around. The owner uses the private key to stamp a file, and anyone with the public key can check that the stamp is genuine and that nothing was changed. The main point is simple: GPG proves who sent something and keeps it private, as long as people check that the public key really belongs to the right person.
Where it is applied
A Linux distribution team publishes thousands of packages through public mirrors that it does not control. To stop a compromised mirror from serving tampered software, the release engineers keep the repository signing key on an offline machine with a hardware token and sign the repository metadata during each release, which lists a SHA-256 hash for every package.
On a user’s server, the package manager downloads the metadata and its signature, then verifies the signature against the distribution key pinned during installation. When an attacker modifies a package on one mirror, its hash no longer matches the signed metadata, and the update fails with a verification error instead of installing the altered code. The team also documents the key fingerprint on its website and in printed installation guides, so new users can confirm it through a second channel.