Last Updated: September 30, 2021
·
12.18K
· asymmetric

Encrypting STDIN using GnuPG

You want to encrypt a string using GnuPG, but you don't want to leave traces of it in your shell's history.

There's a simple solution: by default, if you don't pass an input file, GnuPG will encrypt STDIN.

gnupg --encrypt -o encrypted-file.gpg -r <RECIPIENT>

At this point you can type in the string that you want to encrypt, followed by a newline, after which you have to send an End of Transmission character, a.k.a. CTRL-D.

And that's it, you now have your encrypted string in encrypted-file.gpg.