27

I'm trying to share a GnuPG key pair by importing it into each machine. This is how I'm doing it:

gpg --allow-secret-key-import --import secret.gpg.key
gpg --import public.gpg.key

The keys have been exported with -a.

After doing this, the public key is shown correctly when I do a gpg --list-keys, but the private key isn't (gpg --list-secret-keys).

What am I doing wrong?

By the way: I'm doing this with Puppet, so any solution that doesn't require me to type stuff in (--edit-key and the like) would be appreciated.

1
  • Could you elaborate a bit more on what is wrong with the gpg --list-secret-keys output? There's no flag for GPG to mark a key to be default. It just picks the first one in that list to be the default. If you need to change that behaviour, I can provide an answer.
    – gertvdijk
    Aug 20, 2013 at 12:18

1 Answer 1

26

To change the GnuPG behaviour on what key it selects on signing/encryption, use the default-key configuration parameter with the key ID as the value.

So, for example, with

$ gpg --list-secret-keys 
/home/gert/.gnupg/secring.gpg
-----------------------------
sec   4096R/13371337 2011-01-01 [expires: 2014-01-01]
uid                  Gert van Dijk (1st key) <name@example.tld>
ssb   4096R/31337313 2011-01-01

sec   4096R/12345678 2013-04-23 [expires: 2014-01-01]
uid                  Gert van Dijk (2nd key) <name@example.tld>
ssb   4096R/87654321 2013-04-23

add a line in ~/.gnupg/gpg.conf:

default-key 12345678

or, alternatively, use the long key ID (recommended as short key IDs can have collisions):

$ gpg --list-secret-keys --with-colon
sec::4096:1:ABCDEFAB12345678:2013-01-01:2014-01-01:::Gert van Dijk (2nd key) <user@example.tld>:::

and add a line in ~/.gnupg/gpg.conf:

default-key ABCDEFAB12345678
1
  • 1
    By default the first one of the list of gpg --list-secret-keys will be used as the default key — is that correct?
    – Ini
    Dec 30, 2018 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.