I tried to code sign an iOS application, These are the steps that i followed
security create-keychain -p password ${KEYCHAIN}
security set-keychain-s
Got the same issue but while archiving directly from Xcode. Sharing the solution in case it helps.
Sometimes, Keychain seems to end up in a corrupted state. Using MacOS Sierra too.
Symptoms :
Relogin needed to access Accounts after restarting Xcode
Prompting for password while using Keychain Access for some operations
Keychain Access - Error while accessing login keychain via Change Settings for Keychain ...
What fixes it for me is locking and unlocking (password required) the involved Keychain, login in my case.