I recently generated two new subkeys to put on an external key card. I previously had a master key (usage marked SC) and a single subkey (marked E). This arrangement was worked fine for what I needed in keeping a few local files private. Just now I created two new subkeys using addkey, one signing key and one encryption key. Each of these I transfered to my card using keytocard. That seems to have worked fine and the card does what I expect.

The issue now is I can't figure out how to encrypt a file using my first subkey (key 1). No matter what I specify as a recipient or user (including the subkey id) the resulting file shows up as being encrypted against they key that's now on my card (and only on my card!).

My keyring now looks something like this:

❯❯❯ gpg --list-secret-keys
sec   rsa4096/75267693 2014-07-31 [expires: 2016-02-02]
uid         [ultimate] Caleb Maclennan <[email protected]>
ssb   rsa4096/B89B1E86 2014-07-31 [expires: 2018-07-30]
ssb>  rsa2048/85BD5AD1 2015-10-06 [expires: 2016-10-05]
ssb>  rsa2048/DFE6D89D 2015-10-06 [expires: 2016-10-05]

For encrypting I'm running something like this:

❯❯❯ gpg --recipient B89B1E86 -a -e test.txt

But I've tried all of --default-key, --local-user (-u), and --recipient (-r) including in combination. Any way I shake it, decrypting the result tells be it's encoded with my card key instead:

❯❯❯ gpg -d test.txt.asc
gpg: encrypted with 2048-bit RSA key, ID DFE6D89D, created 2015-10-06
      "Caleb Maclennan <[email protected]>"
gpg: public key decryption failed: Card error
gpg: decryption failed: No secret key

What is the proper procedure to encrypt using a specific subkey?

  • Could it be that the key that you've transfered to the card is the main private key? acording to wiki.debian.org/Subkeys subkeys are like new key pairs but linked to the master key so that with the master key you should be able to decrypt anything ecrypted with the subkeys. Since you are not being able to decrypt the file you have encrypted you can't have the main private key, otherwise you should be able to decrypt anything encrypted with the subkeys.
    – YoMismo
    Commented Oct 6, 2015 at 15:26
  • @YoMismo I was worried at first I'd managed to make that mistake but I checked my commands and the output and don't see any indication of that. If I list my keys or look at the key editor the two new subkeys are listed with a card-no which my original subkey doesn't have. That part seems copacetic.
    – Caleb
    Commented Oct 6, 2015 at 15:39
  • Did you get that information with both --list-keys and --list-secret-keys? because if you can't decrypt you don't have the private one (neither main nor the sub private keys).
    – YoMismo
    Commented Oct 6, 2015 at 15:47
  • @YoMismo Yes, see my latest edit but it shows up when I --list-secret-keys. That being said, being in that list doesn't prove I have the private keys because the last two having been moved to my card have been converted to private key stubs rather than full keys. I think that's what the > is indicating, and it's those two entries that have card numbers associated with them.
    – Caleb
    Commented Oct 6, 2015 at 16:09
  • I've created a feature request on gnupg: dev.gnupg.org/T6381
    – TeNNoX
    Commented Feb 20, 2023 at 13:10

1 Answer 1


To use specific subkeys, and not have GnuPG to resolve the subkey to a primary key, attach ! to the key. For example, to encrypt for the subkey DEADBEEF, use --recipient DEADBEEF!.

Important note: using short key IDs is not recommended due to collision attacks, instead use long key IDs or fingerprints.

  • 2
    Are you sure the ! wasn't interpreted by the shell? Commented Oct 6, 2015 at 16:35
  • 1
    Also, that specifying the main key is resolved to a subkey is a feature -- the main key has delegated responsibility for this action to the subkey, and the subkey binding certificate is proof of that. The ! overrides that. Commented Oct 6, 2015 at 16:38
  • 1
    @SimonRichter Good thought on the shell interpreting the bang; that was indeed the issue. With that accounted for this answer does force the correct oucome. Now my question is is there a way to set this to be by default encryption key so I don't have to constantly set that parameter?
    – Caleb
    Commented Oct 6, 2015 at 17:12
  • @SimonRichter Yes I have delegated E responsibility, but since I have two different subkeys with E function I'm kind of shocked at how hard it was to force it to use one over the other.
    – Caleb
    Commented Oct 6, 2015 at 17:13
  • 1
    You can use the ! syntax in gpg.conf as well, for the default-recipient option. Note that everyone else will still use the key on the card, as that is the most recent key, and gpg assumes the key with the latest creation date to be the preferred encryption key. Commented Oct 6, 2015 at 17:36

You must log in to answer this question.

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