Keytool 无法导入证书

Keytool unable to import certificate

在尝试导入证书时出现无法导入的错误,因为本例中的别名 (tomcat) 已经存在

$ keytool -import -v -alias tomcat -file tomcat.crt -keystore ../keystore -storepass changeit
keytool error: java.lang.Exception: Certificate not imported, alias <tomcat> already exists
java.lang.Exception: Certificate not imported, alias <tomcat> already exists
        at sun.security.tools.keytool.Main.addTrustedCert(Main.java:2644)
        at sun.security.tools.keytool.Main.doCommands(Main.java:1006)
        at sun.security.tools.keytool.Main.run(Main.java:340)
        at sun.security.tools.keytool.Main.main(Main.java:333)
pvaddepa.wb10d1.koala> (/web/home/wb10d1/companyCA)

当我尝试查找别名时却找不到 -

pvaddepa.wb10d1.koala> (/web/home/wb10d1/companyCA)
$ keytool -list -storepass changeit

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

companycaroot, Feb 27, 2016, trustedCertEntry,
Certificate fingerprint (SHA1): 44:6C:91:DF:F9:D6:C4:D2:F6:74:0C:5E:7E:25:2B:61:A8:EF:97:A4

我引用了一个similar question on SO,但是删除后结果没有改变

我认为您没有指向同一个密钥库。 您可以将要打开的密钥库作为参数添加到 keytool 命令吗?我的意思是:

keytool -list -storepass changeit <strong>-keystore ../keystore</strong>

默认情况下,使用的密钥库是 .keystore,它与您尝试导入证书的密钥库 (../keystore) 不同。

如果您列出文件夹的内容 (/web/home/wb10d1/companyCA?),您会找到一个名为 .keystore 的文件,但如果您列出父文件夹的内容,您会发现 keystore 其中别名 tomcat 的证书确实存在。