Import P12 file on Mac OS X with CLI

目的:通过命令行倒入p12证书

Apple为了安全,在ssh登录时,是不允许读取Keychains(钥匙串)的,所以 security unlock-keychain 这行命令就很重要了。比如在Pipeline构建打包前,先解锁Keychains。

1.解锁

1
2
3
4
5
6
7
#方式一: 命令行中不含密码,交互方式
➜ security unlock-keychain /Users/<Your_Name>/Library/Keychains/login.keychain-db
password to unlock /Users/<Your_Name>/Library/Keychains/login.keychain-db:

#或者命令行中包含密码的方式
➜ security unlock-keychain -p <Mac_Login_PWD> /Users/<Your_Name>/Library/Keychains/login.keychain-db
➜ security list-keychains -s /Users/<Your_Name>/Library/Keychains/login.keychain-db

2.导入

1
2
3
4
5
6
7
#方式一: 命令行中不含密码,交互方式
#会有弹窗,提示输入 P12文件的密码
➜ security import ~/Desktop/xxx.p12 -k /Users/<Your_Name>/Library/Keychains/login.keychain-db
1 identity imported.
#或者命令行中包含密码的方式
➜ security import ~/<Your_Path>/xxx.p12 -k /Users/<Your_Name>/Library/Keychains/login.keychain-db -P <P12_Password>
1 identity imported.

3.其他

删除

1
2
3
4
##先展示证书,获取SHA1值; -p 可指定类型
security find-identity -p codesigning /Users/<Your_Name>/Library/Keychains/login.keychain-db
##根据SHA1值删除对应的证书
security delete-certificate -Z <Your_SHA1>

更过 security 用法,查看 security --helpsecurity find-identity --help


More ref:
https://www.cnblogs.com/pixy/p/4817579.html

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~