Search code examples
bashmacossshkeychainaccess-control-list

`security unlock-keychain` from a bash script


On MacOSX, if I ssh in and run the command:

security -v unlock-keychain -p <password> <keychain_path>

The keychain unlocks and all is well with the world.

If I put that same command into a bash script and run

bash test.sh

I get prompted for the password.

How can I get around this?


Solution

  • You need to explicitly let your script test.sh access your keychain.

    • Open the Keychain Access
    • Right click on the private key
    • Select "Get Info"
    • Select "Access Control" tab
    • Click "Allow all applications to access this item"
    • Click "Save Changes"
    • Enter your password
    • Enjoy

    Credits: Running xcodebuild from a forked terminal