After exporting my private key, I moved my private key on a smart card using keytocard. This worked fine, and I could sign and use GnuPG as expected.
Now I would like to go back to have the private key in my GnuPG data base. Since I have the private key backed up, I thought this should be easy, and tried to simply import it:
gpg --import-ownertrust mybackup
However, this seems not to help. The key has still the card-no attached, and when I try to sign something GnuPG asks for the card.
Even deleting the key and reimport seem not to help:
$ gpg --expert --delete-keys <KEYID>
$ gpg --edit-key <KEYID>
gpg (GnuPG) 2.1.11; Copyright (C) 2016 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
gpg: key "<KEYID>" not found: No public key
$ gpg --import-ownertrust mybackup
gpg: key <KEYID>: secret key imported
gpg: Total number processed: 5
gpg: imported: 1
gpg: unchanged: 1
gpg: secret keys read: 5
gpg: secret keys imported: 1
gpg: secret keys unchanged: 2
With that, it seems that GnuPG imported the key. But if I try e.g. signing, GnuPG still asks for the smart card. Also --edit-key still shows "card-no". It seems as if this information is not removed using the delete-key operation above. How can I restore the private key without a reference to the smart card?
--import, however, I end up with the same result, card-no is still set and when I try to sign something, it immediately asks for the card.As a test I imported the same private key export file on a second host, it worked fine on that host... So it seems that the card-no/key id is still part of the gnupg database, and sticks around after restoring the key.
– falstaff Apr 09 '16 at 05:00gpg --expert --delete-keysas this was the only way which worked. My GnuPG version is 2.1.11. When I use--delete-secret-and-public-keysor--delete-secret-keysI get the errorgpg: deleting secret key failed: Not possible with a card based key– falstaff Apr 09 '16 at 06:44--export), deleting all gpg files and theprivate-keys-v1.dsubdirectory reimported the public key and the older private key backup. With thatgpg --edit-key <KEYID>no longer shows the card-no, and I can use the private key without using the card... – falstaff Apr 09 '16 at 06:48gpg --exportonly export public keys, not the secret ones. GnuPG 2.1 stores private keys in thepubring.kbxorpubring.gpgfile (it can work with both formats, while.kbxis the newer one). Anyway, as I understand you've been able to resolve the issue by deleting the key and importing again? – Jens Erat Apr 09 '16 at 10:21Yeah, even though GnuPG 2.1 is able to merge secret keys, iit still asked me to provide the card after reimporting the secret key...
– falstaff Apr 09 '16 at 20:17