security - macOS


Overview

The security command is a powerful tool for managing security settings and credentials on macOS. It allows users to view, add, and remove security policies, certificates, keys, and passwords from the system keychain.

Syntax

security [option] [command] [arguments]

Options

| Option | Description | Default |
|—|—|—|
| -h, --help | Print help message | N/A |
| -v, --verbose | Enable verbose output | False |
| -d, --debug | Enable debug output | False |
| --system | Operate on the system keychain | False |
| --user | Operate on the user keychain | False |

Flags

| Flag | Description |
|—|—|
| -a | Replace existing items |
| -c | Create new items |
| -D | Delete items |
| -i | Display item information |
| -k | Use key instead of passphrase |

Examples

Add a password to the keychain

security add-generic-password -a 'GitHub Account' -s 'github.com' -U 'username' -w 'password'

Retrieve a password from the keychain

security find-generic-password -s 'github.com' -U 'username'

Delete a password from the keychain

security delete-generic-password -s 'github.com' -U 'username'

Common Issues

  • Item not found: Ensure the item is in the correct keychain (system or user) and specify the correct search parameters.
  • Access denied: Check permissions and verify that the current user has access to the keychain.

Integration

  • With sudo: Use sudo security to make changes to the system keychain.
  • With Keychain Access GUI: The security command can be used to automate tasks typically performed through the Keychain Access graphical interface.
  • keychain: Manage keychain items through a graphical interface.
  • certmgr: Manage certificates in the keychain.
  • openssl: Perform cryptographic operations.