How to change the password of a keychain item from the Terminal

keychainpasswordSecuritysshterminal

I am able to list the password of a particular keychain item, but I need to be able to change the password using the Terminal. I intend to write a small script that will automate such a process.

Note: I need to be able to do that using the Terminal only without any GUI!

To display the password of my keychain item, I do the following:

security find-internet-password -gs my.site.com | grep "password:"

The above command works nicely. How do I change this password? For now, let's assume that the security and Keychain Access.app applications have full access to the keychain item. I eventually need to find a way to give access to that keychain item via the Terminal, without any pop-ups/GUI. I have Administrator \ sudo rights to this Mac machine.

Thank you!

Best Answer

If you create the password with the security utility, you can also update it.

security add-internet-password -a 'someuser@domain' -w 's0m3passw0rd' -U -s 'www.some.site -p '/optional/path' -T '/Applications/Google Chrome.app/'

you can update it with the -U flag:

security add-internet-password -U -a 'someuser@domain' -w '0therp4ssw0rd' -U -s 'www.some.site -p '/optional/path' -T '/Applications/Google Chrome.app/'

I've not found a reliable way to update passwords created by other means then the security utility. The -T flag should of course point to the application(s) you want to give access, the -T flag can be repeated multiple times for multiple applications. The -a (accountname) flag can also be any form that your username has.