How do I import a private key into GPG so that it becomes the default key?

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

1 Answer

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) <>
ssb 4096R/31337313 2011-01-01
sec 4096R/12345678 2013-04-23 [expires: 2014-01-01]
uid Gert van Dijk (2nd key) <>
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) <>:::

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

default-key ABCDEFAB12345678
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like