brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: gpg --symmetric and --encrypt protect a file with a passphrase or a key

Security
~/tips/tip-security-gpg-encrypt-symmetric-file

gpg --symmetric --armor --output secret.txt.asc secret.txt

Encrypts a file with GnuPG, either with a passphrase or for someone's public key.

Sometimes you just need to send a file that nobody else should read. GnuPG can encrypt it with a passphrase, or to the public key of a recipient.

gpg --symmetric --armor --output secret.txt.asc secret.txt
gpg --encrypt --recipient [email protected] --output secret.txt.gpg secret.txt
gpg --decrypt --output secret.txt secret.txt.gpg

--symmetric (-c) encrypts with a passphrase instead of a public key. The manual says the default cipher is AES-128, which --cipher-algo can change. --encrypt (-e) encrypts to a public key, and --recipient (-r) names whose. That key must already be in your keyring.

By default the output is binary OpenPGP. --armor produces ASCII text that you can paste into a mail. --output names the result, and --decrypt reverses it.

The caveat is that the original stays where it is. GnuPG does not remove secret.txt, so the plain file is still on the disk until you delete it yourself. Lose the passphrase or the private key, and the encrypted file is gone for good. The manual also notes that gpg caches the passphrase used for symmetric encryption, so a later decrypt may not ask again. --no-symkey-cache turns that off, which is worth doing on a shared machine.

Further reading: GnuPG: gpg(1) manual

More Security tips tcpdump -nn -r capture.pcap port 53 mkcert -install Strict-Transport-Security: max-age=0 Referrer-Policy: strict-origin-when-cross-origin wp super-admin list All Security tips (79) All topics

Link