Encrypt and decrypt a file with `gpg`

The forgotten one-liner for password-protecting a single file without creating a zip archive: GnuPG's symmetric mode is built into every distro.

LinuxprivacygpgencryptionLow risk
Run `gpg -c file` to encrypt with a passphrase (creates file.gpg), then `gpg -o file -d file.gpg` to decrypt it back.

01Command

Command
$ gpg -c secret.txt

02What it does

`gpg -c` prompts twice for a passphrase and writes an AES-encrypted .gpg file next to the original, leaving the original untouched — delete it yourself after encrypting. To encrypt for someone else instead of with a shared password, use `gpg -e -r their@email file` with their public key. Extra flags worth remembering: `-a` produces ASCII-armored output safe for pasting into email, and `--batch --yes --passphrase-fd 0` enables scripted (non-interactive) use.

03Risk

RiskLow risk
RequirementsRequires gpg (GnuPG, preinstalled on virtually all Linux distros)
!Warning: There is no recovery path: if you forget the passphrase the .gpg file is cryptographically unrecoverable.

04Undo

Undo
$ gpg -o secret.txt -d secret.txt.gpg

05Sources

  • gpg(1) — OpenPGP encryption and signing tool
    Ubuntu Manpages · technical · 2026-09-17
    Evidence: Documents -c (symmetric encryption with passphrase), -d (decrypt), -e (public-key encrypt) and -o (output file)
  • GnuPG — Debian Wiki
    Debian Wiki · vendor-doc · 2026-09-17
    Evidence: Walkthrough of symmetric file encryption with gpg -c and decryption with gpg -d

Last verified: 2026-09-17 · Category: Security & Privacy