security list-keychains print:


but the same command from cron return:


from cron I tried

security default-keychain -s "/Users/vitaly-zdanevich/Library/Keychains/login.keychain-db && security list-keychains"

but result is the same.

In the help of cli-utility security I did not found any other way to explicitly set the path to the db.

Yes I know that Apple says that better way is to use launchd instead of cron, but I сurious to know - it is possible to manipulate my Keychain from cron?


Read the --help of the command that you intended to use:

$ security delete-generic-password --help
delete-generic-password: illegal option -- -
Usage: delete-generic-password [-a account] [-s service] [options...] [keychain...]
    -a  Match "account" string
    -c  Match "creator" (four-character code)
    -C  Match "type" (four-character code)
    -D  Match "kind" string
    -G  Match "value" string (generic attribute)
    -j  Match "comment" string
    -l  Match "label" string
    -s  Match "service" string
If no keychains are specified to search, the default search list is used.
        Delete a generic password item.

so the solution is:

* * * * * security delete-internet-password -l 'git-codecommit.us-east-1.amazonaws.com' '/Users/vitaly-zdanevich/Library/Keychains/login.keychain-db'

last arg string - is it the path to the Keychain db.


There is one another way of giving cron job the access to our keychains. When you add the password using security add-generic-password -s SERVICE -a USERID -w PASSWORD, you have to first run the script manually to give "always allow" permission to python to access the keychains and then go to your keychains from app launcher and copy that service and password from login.keychians to syste,.keychains as cronjob by default looks into system keychains and not login keychains. This worked for me. Hope it helps!

  • 2
    Can you please elaborate your answer, right now it's rather hard to follow/understand. Step-by-step instructions work best. – nohillside Dec 8 '17 at 19:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .