Add/import certificate with password via command l

2019-02-13 11:05发布

问题:

I'm trying to import a .pfx certificate via command line. This certificate is secured by a password. Is there a way to do this in terminal? I'm running OS X 10.8.

When I use this command I get the default pop-up asking for the password:

security import certificate.pfx -k ~/Library/Keychains/login.keychain

When I use this command:

security import certificate.pfx -k ~/Library/Keychains/login.keychain -P password

I get this error:

SecKeychainItemImport: MAC verification failed during PKCS12 import (wrong password?)

I'm sure the password is correct because it works if I enter it manually.

Thanks!

回答1:

Got it!

The password starts with a dollar and I didn't escape it with a \.

So let's say the password is $tup1dP@ssw0rd the command has to be:

security import certificate.pfx -k ~/Library/Keychains/login.keychain -P \$tup1dP@ssw0rd