79

Is it possible to copy a certificate to a machine running OS X Snow Leopard, add it to the System Keychain, then set it to "Always Trust via SSH?"

And if so... how?

1

2 Answers 2

96

To import a trusted certificate use the terminal command

sudo security add-trusted-cert \
  -d \
  -r trustRoot \
  -k /Library/Keychains/System.keychain \
  <certificate>

This will add a trusted certificate to the System.keychain. You should modify the options and paths to suit your situation. See the man page for security for more information.

↬ Rich Trouton, Adding new trusted root certificates to System.keychain

9
  • The quotes messed me up for some reason, removed them and all was well. Commented Apr 17, 2014 at 0:02
  • 9
    Thanks muchly! Just a note: One can also add to "$HOME/Library/Keychains/login.keychain"
    – user110537
    Commented Jan 21, 2015 at 13:48
  • 10
    What is the difference between security add-trusted-cert and security import?
    – Nepoxx
    Commented Oct 10, 2019 at 15:14
  • 1
    fyi to add a trusted CA to only the current user's Login keychain you don't need to sudo but you will be asked for your password: security add-trusted-cert -d -r trustRoot -k ~/Library/Keychains/login.keychain-db /tmp/my-root-ca.cer
    – jamshid
    Commented Feb 13, 2021 at 3:32
  • 2
    Does this really work from a pure terminal? security want's to do some interactions despite the sudo.
    – Martin
    Commented Dec 14, 2021 at 15:09
9

The selected answer does not really work on newer versions of MacOS.
The correct command now is:

sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain <certificate>

Note: tested with MacOS 12(Monterey) and MacOS 13(Ventura)

3
  • Welcome to Ask Different. Your answer could be improved by referencing which versions of macOS onward this change applies to. As it stands 'newer versions' doesn't provide a reference point, especially as the OP was asking about Snow Leopard. That was a long time ago (2009). Commented Sep 24, 2022 at 8:12
  • 2
    updated with a note as requested
    – ibacalu
    Commented Nov 14, 2022 at 8:41
  • 2
    What format did you have to use? For pem format, your command yielded SecTrustSettingsSetTrustSettings: One or more parameters passed to a function were not valid.
    – volvox
    Commented Mar 27, 2023 at 15:58

You must log in to answer this question.