4

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?

mfaani
  • 33,269
  • 19
  • 164
  • 293
CleverPatrick
  • 9,261
  • 5
  • 63
  • 86

1 Answers1

8

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

oliv
  • 12,690
  • 25
  • 45
  • Do I need to do this to every private key listed in the "keys" section of Keychain Access? – CleverPatrick Mar 16 '18 at 12:49
  • 2
    @CleverHuman I never did that, and I won't... I would consider this as a security issue if one of my script would access any of my private keys. I try to stick to the 1 function/1 key paradigm. – oliv Mar 16 '18 at 14:06