Import gpg secret keys from a backup (without restoring it)
I have gpg private keys on my desktop computer that I can't start anymore but I have a backup that includes the .gnupg directory.
I don't want to override the whole .gnupg directory on my laptop, just import the secret keys. Normally, to transfer keys, I would run gpg --export but I can't since I have no running computer with these keys.
In ~/.gnupg/private-keys-v1.d of the backup, there are a number of .key file, but running on my laptop gpg --import xxx.key for each gives "gpg: no valid OpenPGP data found.".
Are these files not where the secret keys are? How can I import those secret keys?
> gpg --export but I can't since I have no running computer with these keys.
Yes you can. You can tell GnuPG to use whatever it is you want - just specify it like it's an "alternate" keyring location.
Start off with gpg --no-default-keyring
That tells GPG "don't look in the normal spot."
Then add:
gpg --no-default-keyring --keyring=/this/is/where/my/amazing/old/file/lives/at
That tells GPG to look somewhere else for the keyring files, which would be your old pubring.kbx
Then try:
gpg --no-default-keyring --keyring=/this/is/where/my/amazing/old/file/lives/at --list-keys
And you should see the keys listed.
And --export should work too:
gpg --no-default-keyring --keyring=/this/is/where/my/amazing/old/file/lives/at --export blah-blah-blah
The whole idea revolves around telling GPG to look elsewhere to export the keys.
Then you can drop all that and do the usual gpg --import.
Thanks for the explanations.
Apparently the --keyring option wants a file, not a directory.
If I run
gpg --no-default-keyring --keyring=/path/.gnupg/pubring.kbx --list-secret-keys
I get nothing. There does not seem to be any equivalent keyring file for private key. However, from "man gpg", I managed to get it work with the --homedir option:
gpg --no-default-keyring --homedir=/path/.gnupg --list-secret-keys
and
gpg --no-default-keyring --homedir=/path/.gnupg --export-secret-keys
At first, I was confused and thought I should put the user home directory after --homedir, but it is the .gnupg directory that is needed. The first sentence of the man page for that option is rather misleading but one can guess from the second sentence.