19

I've try install .p12 cert to my macos use command line.

I can install .cer

sudo certtool I Certificates.p12 d

but it doesn't work on computers where this cert is not generated. As I see i should use .p12 But how can I install .p12 ?

I've tried to use

security add-certificates "/Users/$NAME/Library/Keychains/login.keychain" "$CERT_PATH"

But result same as previous command. Can't install .p12

Please help.

Thanks,

3 Answers 3

54

It looks like you can do this using the import command. I've managed to do the following:

security create-keychain -p password bobbins.keychain
security add-certificates ./MyCertificate.cer

security unlock-keychain -p password bobbins.keychain
security import ./MyPrivateKey.p12 -k bobbins.keychain -P privateKeyPassword

I found I had to unlock the keychain, otherwise it prompted for the keychain password.

Hope this helps.

3
  • You may also find it helpful to specify the '-a' option for importing your private key. This allows you to specify the path to an application that's allowed to use it without entering the password.
    – Sojurn
    May 31, 2014 at 6:11
  • 1
    According to the documentation the allow flag is'-A'. The lowercase is for another purpose.
    – Jessedc
    Aug 28, 2014 at 4:46
  • 2
    The two options (at least as of macOS 10.12): -A Allow any application to access the imported key without warning (insecure, not recommended!) -T Specify an application which may access the imported key (multiple -T options are allowed)
    – gregmac
    Jun 15, 2017 at 14:49
34

This will import the bundle to the default keychain:

security import ./bundle.p12 -P secretPassword

secretPassword is the p12 file encryption password.

While the answer by Stuart should work, it is not required to create another keychain first.

1

It's so simple. I've managed to do the following:

security import ./dev_account.p12 -P password -A

It will not prompt for the keychain password. It's works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.