3

I'm maintaining several keys in a keyring and I regularly want to encrypt a file with every key in the keyring as a recipient. What is the best way to accomplish this if I do not want to specify each recipient individually with the --recipient or -r options?

1
  • How about to write a bash/batch script? What is your operating system you're working on?
    – arminb
    Nov 20, 2012 at 2:40

1 Answer 1

4

I'd start with something like this to auto-detect all the pubkeys in your keyring:

[rsaw ~]$ gpg --list-keys --with-colons --fast-list-mode | awk -F: '/^pub/{printf "-r %s ", $5}'
-r 8364FDE4388D0935 -r 8F5B84CD292F9E32 -r EE3656DD5B0E2954 -r F576F163ABF75D93

That should give you enough -- there are tons choices for how to proceed. One route: create a wrapper that runs gpg with that plus any args you pass it, e.g. add the following to ~/.bashrc:

g(){ gpg $(gpg --list-keys --with-colons --fast-list-mode | awk -F: '/^pub/{printf "-r %s ", $5}') "$@"; }

Example of running it:

[rsaw ~]$ g -aveo /tmp/issue.asc /etc/issue
gpg: using subkey BDE204E4 instead of primary key ABF75D93
gpg: using PGP trust model
gpg: This key belongs to us
gpg: using subkey E2E92BD7 instead of primary key 5B0E2954
gpg: This key belongs to us
gpg: using subkey 0EAE2434 instead of primary key 292F9E32
gpg: This key belongs to us
gpg: using subkey 9E0428AA instead of primary key 388D0935
gpg: This key belongs to us
gpg: reading from `/etc/issue'
gpg: writing to `/tmp/issue.asc'
gpg: RSA/AES256 encrypted for: "9E0428AA Ryan Sawhill <rsaw@devnull>"
gpg: RSA/AES256 encrypted for: "0EAE2434 Obama Mo <[email protected]>"
gpg: RSA/AES256 encrypted for: "E2E92BD7 Mitt Rom <rom@devnull>"
gpg: ELG/AES256 encrypted for: "BDE204E4 Bill C <clinton@nowhere>"

This is nice if you always encrypt files and save output to files; otherwise, it might be simpler to have your script/function ONLY run the original detection-command -- this would allow more flexibility, e.g.:

gpg $(g) -aveo </tmp/myfile
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .