Keychain always asking for password when running codesign

code-signing, codesign, keychain, macos

Solution

When you use `security unlock-keychain -p $PASSWORD $KEYCHAIN` the keychain will be unlocked, but, for only 5 minutes, due to an automatic relock. To keep the keychain unlocked permanently you need to use `security set-keychain-settings $KEYCHAIN`.

For completeness of this answer, I would also recommend that you use `security import $CERT -k $KEYCHAIN -P "$CERTPASSWORD" -T /usr/bin/codesign` to grant `/usr/bin/codesign` access to your certificate.

Problem

I just got my certificate installed on a Mac OS X 10.7 and wrote a script that runs `codesign` on a number of files after compiling my project. I created a new keychain and disabled the option for locking it after a certain period of time. It looks like the login keychain. But every time my script runs the codesign command the following error occurs: `<filename>: User interaction is not allowed.` If I start a shell, unlock the keychain with `security unlock-keychain <path>` and then run the script manually, it works. The question is how to keep the keychain always unlocked so that my automatic build can sign the files?

Original source

Related problems