use*_*471 5 security macos certificate
简短版本:请提供...的示例security delete-certificate -c <name>(我尝试过security delete-certificate -c "Foo Certification Authority",也尝试过通配符。)
长版:
我想要做的是:替换或覆盖现有证书。
有人可以提供一个security用于获取证书的“名称”然后security delete-certificate -c <name>用于删除它的示例吗?我已经尝试了一些东西,<name>但还没有能够提供与我想要删除的证书相匹配的东西。
或者,如果我使用security add-trusted-cert -d -r trustRoot -k <keychain> <certificate>它是否会简单地覆盖任何现有的同名证书?如果是这种情况,那么我想我不需要知道如何按名称删除旧的。
(我更喜欢处理名称而不是 SHA,因为它使事情更具人类可读性)
小智 9
这个答案几乎是逐字来自 stack apple 网站:
*在尝试任何操作之前备份钥匙串。
列出根证书:
sudo security dump-keychain /System/Library/Keychains/SystemRootCertificates.keychain
Run Code Online (Sandbox Code Playgroud)
在转储中查找要删除的证书的名称或 SHA-1 哈希值:
Usage: delete-certificate [-c name] [-Z hash] [-t] [keychain...]
-c Specify certificate to delete by its common name
-Z Specify certificate to delete by its SHA-1 hash value
-t Also delete user trust settings for this certificate The certificate to be deleted
must be uniquely specified either by a string found in its common name, or by its SHA-1 hash. If no keychains are specified to search, the default search list is used.
Run Code Online (Sandbox Code Playgroud)
例如,您可以使用以下命令删除此中国根证书:
sudo security delete-certificate -Z 8BAF4C9B1DF02A92F7DA128EB91BACF498604B6F /System/Library/Keychains/SystemRootCertificates.keychain
Run Code Online (Sandbox Code Playgroud)
我认为 -Z 哈希方法可能更安全,并且建议这样做。您关于覆盖证书的问题很复杂,因为根据证书的不同,它通常不是一个命令可以处理所有情况。苹果网站上有一篇文章,其中包含使用(和不使用)安全性和钥匙串的不同方式的截屏视频。