How do I import a private key into GPG so that it becomes the default key?
Solution 1:
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) <[email protected]>
ssb 4096R/31337313 2011-01-01
sec 4096R/12345678 2013-04-23 [expires: 2014-01-01]
uid Gert van Dijk (2nd key) <[email protected]>
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) <[email protected]>:::
and add a line in ~/.gnupg/gpg.conf
:
default-key ABCDEFAB12345678