GPG

Also known as: GNU Privacy Guard · GnuPG

On this page 7

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.

OperationTypical commandWhat it guarantees
Public-key encryptiongpg --encrypt -r aliceConfidentiality for named recipients
Symmetric encryptiongpg --symmetricConfidentiality with a passphrase only
Detached signaturegpg --detach-signIntegrity and origin, file left untouched
Clear-signed textgpg --clearsignReadable text with an embedded signature
Verificationgpg --verifyChecks signature against a public key
Core GPG operations and their security properties

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.

AlgorithmTypical useNotes
Ed25519Signing and certificationShort keys, fast, current default
Cv25519Encryption subkeysPairs with Ed25519 identities
RSA 3072 or 4096Signing and encryptionBroad compatibility, larger keys
NIST P-256 or P-384Signing and encryptionUsed where NIST curves are mandated
DSA and ElGamalLegacy keys onlyAvoid for new keys
Common key algorithms supported by GnuPG

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.

ApproachTrust modelTypical scope
GPG with OpenPGPWeb of trust or pinned keysFiles, email, software releases
S/MIME with X.509Certificate authoritiesCorporate email
SSH signing keysAllowed signers fileGit commits and tags
SigstoreShort-lived certificates and logsContainer and package signing
Signal protocolSafety numbers per contactEnd-to-end encryption in messaging
GPG compared with related cryptographic tools

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 .asc signature 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.

MistakeConsequenceCorrection
Trusting a short key IDCollisions allow spoofed keysCompare the full fingerprint
No revocation certificateLost key cannot be retiredGenerate one at key creation
Primary key on daily laptopTheft compromises the identityKeep it offline, use subkeys
Ignoring verification outputBad signatures go unnoticedCheck exit codes in scripts
Never-expiring keysAbandoned keys stay validSet and renew expiration dates
Frequent GPG mistakes and how to correct them

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.