How to unlock system keychain in OS X using terminal

Durai Amuthan.H picture Durai Amuthan.H · Apr 7, 2016 · Viewed 8.7k times · Source

I have private key and certificate in system keychain and I want to access it using CodeSign so it needs to be unlocked.

if I try to unlock login keychain using below script then no problem

security unlock-keychain -p password login.keychain

But If I use the same syntax for system.keychain then I get this error security: SecKeychainUnlock The user name or passphrase you entered is not correct.

security unlock-keychain -p password /Library/Keychains/System.keychain

From this what I can see there is no way to enter username in the syntax.

My intention is to unlock the keychain while code-signing the build,so that I won't get prompt like below.In the case of code-signing event in jenkins I'd get error like "User Interaction is not allowed"

I know this problem can be solved by giving access to all apps in keychain But I intend to do it via script itself.

code sign alert

Any help is appreciated !

Answer