Skip to content

security command in MacOS

The security command in MacOS allows users to interact with various security services, including managing keychain items, certificates, keys, and more. This command is essential for tasks such as changing keychain settings, manipulating certificates, and configuring the Keychain Access app. By using the security command in MacOS, users can efficiently handle user authentication, permissions, and security-related operations.

Terminal window
security [options] [command] [parameters]
OptionDescription
-hShow help message
-vVerbose mode
-hPerform hash
-cVerify certificate
-pShow private key
-rRollover keychain
ParameterDescription
keychainNameName of the keychain to use
itemLabelLabel of the item to operate on
commandSpecific security command
Terminal window
security list-keychains

Lists all available keychains on the system.

Terminal window
security show-keychain-info login.keychain

Displays detailed information about a specific keychain file (e.g., login.keychain).

Terminal window
security find-internet-password -gs www.example.com

Searches and displays internet passwords stored for a specific website (e.g., www.example.com).

Terminal window
security add-generic-password -a user -s "Service" -w "Password"

Adds a new generic password item to the keychain with the specified username, service name, and password.

Terminal window
security delete-generic-password -s "Service"

Deletes a generic password item from the keychain based on the specified service name.

Terminal window
security set-key-partition-list -S apple-tool:,apple: -k newpassword login.keychain

Changes the password for a specific keychain file (e.g., login.keychain) to “newpassword”.

Terminal window
security export -k login.keychain -t identities -o private.pem

Exports specific keychain items (identities) from a keychain file (e.g., login.keychain) to a private key file (e.g., private.pem).

Terminal window
security import private.pem -k login.keychain

Imports keychain items (e.g., from a private key file named private.pem) into an existing keychain file (e.g., login.keychain).

To use the security command in MacOS, execute the following command:

Terminal window
security --option <value>

How do I check the validity of a keychain in MacOS?

Section titled “How do I check the validity of a keychain in MacOS?”

To check the validity of a keychain in MacOS using the security command, you can run:

Terminal window
security verify-keychain -k keychain_path

How do I list the keychains in MacOS using security?

Section titled “How do I list the keychains in MacOS using security?”

To list the keychains in MacOS using the security command, you can use the following command:

Terminal window
security list-keychains

How can I find out the default keychain in MacOS with security?

Section titled “How can I find out the default keychain in MacOS with security?”

To find out the default keychain in MacOS using the security command, you can run:

Terminal window
security default-keychain

How do I view the contents of a specific keychain with security in MacOS?

Section titled “How do I view the contents of a specific keychain with security in MacOS?”

To view the contents of a specific keychain in MacOS using the security command, you can use:

Terminal window
security dump-keychain keychain_path

How can I add a keychain in MacOS using security?

Section titled “How can I add a keychain in MacOS using security?”

You can add a keychain in MacOS using the security command by running:

Terminal window
security list-keychains -s new_keychain_path

How do I delete a specific keychain in MacOS with security?

Section titled “How do I delete a specific keychain in MacOS with security?”

To delete a specific keychain in MacOS using the security command, you can execute:

Terminal window
security delete-keychain keychain_path

How do I manage trust settings for certificates in MacOS using security?

Section titled “How do I manage trust settings for certificates in MacOS using security?”

To manage trust settings for certificates in MacOS with the security command, use:

Terminal window
security set-trust-settings -d certificate_path

How can I find the identity preference for a key in MacOS with security?

Section titled “How can I find the identity preference for a key in MacOS with security?”

To find the identity preference for a key in MacOS using security, you can enter:

Terminal window
security find-identity -vp key_name
  • Managing Keychains
  • Checking Code Signatures
  • Verifying System Integrity Protection (SIP)
  • Generating Secure Tokens
  • Managing certificates and keys
  • Checking and managing X.509 certificate trust settings