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.
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.txt02What 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
!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.gpg05Sources
- gpg(1) — OpenPGP encryption and signing toolEvidence: Documents -c (symmetric encryption with passphrase), -d (decrypt), -e (public-key encrypt) and -o (output file)
- GnuPG — Debian WikiEvidence: Walkthrough of symmetric file encryption with gpg -c and decryption with gpg -d
Last verified: 2026-09-17 · Category: Security & Privacy