How can I create Keychain entries via command line?

1

1

I am trying to use the command line to automatically add passwords to the keychain app for various file servers. I was able to use the man security to figure out most of it.

It's creating the keychain with the right info, but when I attempt to connect to said file server in finder I am still prompted to enter the password as if there is no keychain for it.

Here is what I have. What am I missing to get this to work the way I want?

sudo security add-generic-password -a "$EMAIL_USERNAME" -s smb://10.1.50.50 -w "$PASSWORD" -l NY-File-Server \
-D "network password" \
-T /System/Library/CoreServices/NetAuthAgent.app

Daniel

Posted 2015-10-04T01:17:22.133

Reputation: 31

Now that I figure this out I am trying to figure out how to add the keychain to other users on the computer. Any one know a way to point it to another users keychain? The final goal is to be able to add it to a deploy studio workflow and have it add all the sever password keychains to the users on the computer so the end user does't have to type them all one by one. Any Ideas ? – Daniel – 2015-10-05T22:25:47.653

Answers

2

After taking a second look at the option I was able to figure it out. Adding as an Internet password rather the a generic password and setting the protocol worked. Here is the working command:

sudo security add-internet-password -a "$EMAIL_USERNAME" -r "smb " -s "10.1.50.50" -w "$PASSWORD" -D "network password" -l "NY-File-Server" -T /System/Library/CoreServices/NetAuthAgent.app

Daniel

Posted 2015-10-04T01:17:22.133

Reputation: 31

The final goal is to be able to add it to a deploy studio workflow and have it add all the sever password keychains to the users on the computer so the end user does't have to type them all one by one. Any Ideas ?Any one know how I can run this on another user? – Daniel – 2015-12-08T17:28:26.823