Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install .p12 or .cer in console macos

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,

like image 398
Sergey Kopanev Avatar asked Sep 20 '11 13:09

Sergey Kopanev


2 Answers

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.

like image 100
Stuart Ervine Avatar answered Oct 07 '22 02:10

Stuart Ervine


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.

like image 43
Marian Avatar answered Oct 07 '22 01:10

Marian