Script to create keychain entry for current user

New Contributor

I'm in the process of trying to roll out noMAD - One of the features I want to use is for noMAD to be synced to a 802.1x WiFi Keychain Entry.

Because normally this keychain entry isn't created until a user logs in for the first time, I want the entry to be automatically created via the script if it doesn't already exist.

The line I am using is -

sudo -u $netname security add-generic-password -a $netname -D "802.1X Password" -l Workstations-Wifi -s -T /System/Library/SystemConfiguration/EAPOLController.bundle/Contents/Resources/eapolclient

and I am getting -

security: SecKeychainItemCreateFromContent (<default>): Write permissions error.

Does anyone have any idea what I may need to do here? Any help would be appreciated!


Legendary Contributor III

Try this. Make any necessary adjustments.


LOGGED_IN_USER=$(stat -f%Su /dev/console)

netname=$(use whatever you already have here)

/bin/launchctl asuser $LOGGED_IN_UID sudo -iu $LOGGED_IN_USER /usr/bin/security add-generic-password -a $netname -D "802.1X Password" -l Workstations-Wifi -s -T /System/Library/SystemConfiguration/EAPOLController.bundle/Contents/Resources/eapolclient

New Contributor

@mm2270 Thanks, I tried that but am still getting "security: SecKeychainItemCreateFromContent (<default>): Write permissions error."

Any idea? I assume maybe because I need to unlock the users login keychain first before I can save anything to it.

Is it possible to do this?