CertMon

SECURITY & CERTIFICATES

How to trust a self-signed certificate or local CA in Keychain on a Mac

Adding a certificate to Keychain Access does not make your Mac trust it. Trust is a separate setting on the certificate, for your account or for every account on the Mac. Here is how to set it in Terminal and in Keychain Access, which keychain to use, and which apps will then accept the certificate.

Start in Terminal: add the certificate and trust it

For your account only, in the login keychain, trusted for SSL:

security add-trusted-cert -r trustRoot -p ssl \
  -k ~/Library/Keychains/login.keychain-db rootCA.pem

For every account on this Mac, and processes running as root:

sudo security add-trusted-cert -d -r trustRoot -p ssl \
  -k /Library/Keychains/System.keychain rootCA.pem

Check it. The output should end in certificate verification successful.

security verify-cert -c server.crt -p ssl -n myapp.test

From man security:

macOS asks you to confirm with your password or Touch ID. The command waits for that dialog, so it does not work unattended or over SSH; managed Macs push certificates with a configuration profile instead. Do not put sudo in front of the per-user form: it sets trust for the root user, not for you.

To undo: security remove-trusted-cert rootCA.pem (add sudo and -d for the admin form), then security delete-certificate -c "My Local Dev CA" to remove the certificate itself.

In Keychain Access

  1. Open Keychain Access with Spotlight. Since macOS Sequoia it is no longer in the Utilities folder.
  2. Choose File → Import Items…, pick the .pem, .crt or .cer file, and choose the login keychain.
  3. Open the Certificates tab and double-click the certificate.
  4. Expand Trust. Set Secure Sockets Layer (SSL) to Always Trust, or set "When using this certificate" to Always Trust for every purpose.
  5. Close the window and enter your password when asked. The trust setting is saved only then.

A certificate with custom trust shows a small blue plus on its icon, and its details say it is marked as trusted for this account.

Login keychain or System keychain

Root CA or self-signed leaf

Trusting a self-signed leaf works for the one name it covers, but it breaks every time the certificate is regenerated, and you trust it again. Trusting a local root CA is a single decision that covers every certificate it signs, so renewing a site's certificate needs no keychain change.

The cost: anyone who gets the CA's private key can make certificates your Mac trusts. Keep the key out of project folders, and give the CA X.509 Name Constraints so it can only sign development names. With OpenSSL, add -addext "nameConstraints=critical,permitted;DNS:test,permitted;DNS:localhost" when creating the CA. In our test on macOS 26, security verify-cert accepted a myapp.test certificate from such a CA and rejected one it signed for example.com.

Either way, the leaf still needs a Subject Alternative Name for each host, and for Safari the serverAuth extended key usage and a lifetime of 825 days or less. The commands to make one are in How to enable trusted HTTPS on localhost in Safari and Chrome on macOS.

Which apps use the keychain

The easier way with CertMon

CertMon does all of this on first launch. It creates a root CA whose private key stays in your login keychain, not in a file, limits it with Name Constraints to .test and .localhost names, and trusts it for SSL for your account only, so nothing changes system-wide. You confirm once with your password. The Trust & Devices tab shows the trust status, Repair Trust puts it back if it is lost, and Export CA Certificate (.crt) saves the root for Firefox, Node or a container.

CertMon dashboard listing four .test sites, each forwarding to a localhost port and marked Active and Trusted.
One trusted root, and a certificate for every .test site.

Download CertMon free trial

Related guides