Selecting subkeys in batch mode

gnupg.20.miller_2555 at spamgourmet.com gnupg.20.miller_2555 at spamgourmet.com
Thu Oct 7 22:38:00 CEST 2010


Hi -

    I have a public key with two encryption subkeys (see note below). I am
attempting to clobber together a bash script to select a given subkey and
use that subkey for encryption. Using the following sample key and sample
script, `afile` is encrypted with subkey CCCCCCCC (and not the expected
BBBBBBBB subkey). Note that no matter what subkey register slot I provide to
`--edit-key` in the sample script, `gpg` always encrypts using the CCCCCCCC
subkey. How can I selectively use a given encryption subkey in a
noninteractive session?

    Sample public key:
        pub   4096R/AAAAAAAA 2009-08-11 [expires: 2020-12-31]
        uid                  Name (Comment) <email>
        sub   4096g/BBBBBBBB 2009-12-25 [expires: 2010-12-31]
        sub   4096R/CCCCCCCC 2010-09-25 [expires: 2010-11-30]

    Sample script:
        #!/bin/bash
        gpg --quiet --batch  --edit-key AAAAAAAA "key 1";  # Select subkey
BBBBBBBB (I also tried a value of "key 2")
        cat afile | gpg --quiet --batch  --hidden-recipient AAAAAAAA
--passphrase-file sfile --sign --encrypt -  > newfile;

Note: It was not my decision to use two encryption subkeys, but I've been
requested to use each under certain circumstances. Also, anyone the copies/
pastes the above code should avoid the use of the `--passphrase-file` option
as I am only using this in testing.

Many thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20101007/250dd3be/attachment.htm>


More information about the Gnupg-users mailing list