security password management

Manage password items.

Syntax: Find a generic password item.

      find-generic-password [-h] [-a account] [-s service] [-options...] [-g] [-keychain...]
            

Syntax: Delete a generic password item.

      delete-generic-password [-h] [-a account] [-s service] [-options...] [-keychain...]

   Options   
      -a account      Match account string
      -c creator      Match creator (four-character code)
      -C type         Match type (four-character code)
      -D kind         Match kind string
      -G value        Match value string (generic attribute)
      -j comment      Match comment string
      -l label        Match label string
      -s service      Match service string
      -g              Display the password for the item found


Syntax: Delete an internet password item.

      delete-internet-password [-h] [-a account] [-s server] [options...] [keychain...]

            
Syntax: Find an internet password item.

      find-internet-password [-h] [-a account] [-s server] [options...] [-g] [keychain...]
            
   Options
      -a account      Match account string
      -c creator      Match creator (four-character code)
      -C type         Match type (four-character code)
      -d securityDomain      Match securityDomain string
      -D kind         Match kind string
      -j comment      Match comment string
      -l label        Match label string
      -p path         Match path string
      -P port         Match port number
      -r protocol     Match protocol (four-character code)
      -s server       Match server string
      -t authenticationType     Match authenticationType (four-character code)
      -g              Display the password for the item found

Examples

Add to keychain:

$ security add-generic-password -a $USER -s 'PAwindevcluster' -w this_is_the_secret

Read from the keychain:

$ security find-generic-password -a "$USER" -w -s 'PAwindevcluster'
this_is_the_secret

Save the password to an environment variable 'P64', Be aware that it is possible to view the environment using ps -E, which could expose the password:

$ export $(echo "P64"="$(security find-generic-password -a "$USER" -w -s 'PAwindevcluster')")

Delete from the keychain:

$ security delete-generic-password -a "$USER" -s 'PAwindevcluster'

“The man who looks for security, even in the mind, is like a man who would chop off his limbs in order to have artificial ones which will give him no pain or trouble” ~ Henry Miller (The Rosy Crucifixion I )

Related macOS commands

Local man page: security - Command line help page on your local machine.
security - Administer Keychains, keys, certificates and the Security framework.


 
Copyright © 1999-2025 windevcluster.com
Some rights reserved