I have two smart cards: SCard1 and SCard2. The same keys are stored on both of them.
One of the feature I use the most is SSH authentication to access multiple servers. But I cannot use the second one after having used the first both of the smart cards (not simultaneously) on the same computer.
The following message is displayed:
Please remove the current card and insert the one with serial number
[a long ID containing the SCard1 identification number]
Steps to reproduce the issue
Let's prepare a clean environment.
$ export GNUPGHOME=/tmp/gnupg
$ mkdir /tmp/gnupg && chmod go-rwx /tmp/gnupg
$ curl [public key URL] | gpg --import
gpg: keybox '/tmp/gnupg/pubring.kbx' created
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6194 100 6194 0 0 2408 0 0:00:02 0:00:02 --:--:-- 2408
gpg: /tmp/gnupg/trustdb.gpg: trustdb created
gpg: key 3D5DDE26A0B55831: public key imported
gpg: Total number processed: 1
gpg: imported: 1
With SCard1 plugged
Then I insert my SCard 1.
$ ls /tmp/gnupg/private-keys-v1.d/
$ gpg --card-status
Reader ...........: Yubico Yubikey 4 OTP U2F CCID 00 00
Application ID ...: [SCard1 identification number]
blahblah
ssb> rsa2048/467299D324A21B24 created: 2017-01-10 expires: 2018-01-10
card-no: [SCard1 identification number]
ssb> rsa2048/11771A79F4B85B41 created: 2017-01-10 expires: 2018-01-10
card-no: [SCard1 identification number]
ssb> rsa2048/F31D41149A84B062 created: 2017-01-10 expires: 2018-01-10
card-no: [SCard1 identification number]
The last key is used for authentication.
$ ls /tmp/gnupg/private-keys-v1.d/
somehash1.key somehash2.key somehash.3.key
I guess those hashes come from the keys I've stored on my smart card.
$ gpg -K
/tmp/gnupg/pubring.kbx
sec# rsa4096 2017-01-10 [SC] [expires: 2019-01-10]
[primary key ]
ssb> rsa2048 2017-01-10 [S] [expires: 2018-01-10]
ssb> rsa2048 2017-01-10 [E] [expires: 2018-01-10]
ssb> rsa2048 2017-01-10 [A] [expires: 2018-01-10]
$ ssh example.com hostname
*** asked to enter pin
example.com
Everything works as expected.
With SCard2 plugged
Let's unplug SCard1 and plug SCard2.
$ ssh example.com hostname
And the following message is displayed:
Please remove the current card and insert the one with serial number
[a long ID containing the SCard1 identification number]
Please note I've got the same result when I insert first SCard2, and then SCard1.
Part of a solution
Some searching on the Internet made me understand that the "key stubs" are stored in ~/.gnupg/private-keys-v1.d/
. Deleting the whole directory solved the problem. Maybe just deleting one of the .key
would do the trick.
The question
Is it possible to use both of the keys without deleting any file?