I recently upgraded one of our Mac Mini build servers to macOS Sierra. After doing so, I noticed something very strange happening when trying to sign our app builds. The signing process was failing for some reason. I went to check the keychain using the security command to see if I could see what was going on, and if it couldn’t find the relevant certificates and private keys.
I tried exporting, deleting, re-importing the entries in my keychains. I tried creating new login keychain. Rebooting, etc. Still couldn’t work out why it was displaying the duplicate keychain entries.
After a lot of looking about, I found the issue. There was a copy of the private key for ‘Legacy Parts Corporation’ in my system keychain. Not the certificate… hence why it didn’t show up above. But for some very unknown reason, having a duplicate key in another keychain without the corresponding certificate causes macOS to get a bit confused and show the cert multiple times.
Deleting the private key from the system keychain and suddenly things look much better again: