I want to import a PGP public key into my keychain in a script, but I don't want it to write the contents to a file. Right now my script does this:
curl http://example.com/pgp-public-key -o /tmp/pgp && gpg --import /tmp/gpg
How could I write this script so I can just call gpg --import
and import the public key as a string? Thank you for your help.
gpg --import
knows two ways of operation: it can either read from a file (for example gpg --import key.gpg
) or -- if no file name is passed -- read from STDIN. curl
on the other hand will print the fetched document to STDOUT if no -o
parameter is given. Putting both together with a pipe will directly stream the results from curl
into gpg --import
:
curl http://example.com/pgp-public-key | gpg --import