Linux:keytool 说 "Unrecognized command: -exportcert"

Linux: keytool says "Unrecognized command: -exportcert"

Facebook API or in documentation for Android developers 的文档中提到您应该使用 keytool 命令,例如。 g.:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v

但是粘贴到终端时只能看到错误:

Unrecognized command: -exportcert
Usage:  keytool [COMMAND] [-- COMMAND]...
Manage private keys and public certificates.

Available commands:
  -genkey         Generate a Key Entry, eventually creating a key store.
                    [-alias ALIAS] [-keyalg ALGORITHM] [-keysize KEY_SIZE]
                    [-sigalg ALGORITHM] [-dname NAME] [-keypass PASSWORD]
                    [-validity DAY_COUNT] [-storetype STORE_TYPE]
                    [-keystore URL] [-storepass PASSWORD]
                    [-provider PROVIDER_CLASS_NAME] [-v].
  -import         Add Key Entries and Trusted Certificates.
                    [-alias ALIAS] [-file FILE] [-keypass PASSWORD]
                    [-noprompt] [-trustcacerts] [-storetype STORE_TYPE]
                    [-keystore URL] [-storepass PASSWORD]
                    [-provider PROVIDER_CLASS_NAME] [-v].
  -selfcert       Generate a self-signed Trusted Certificate.
                    [-alias ALIAS] [-sigalg ALGORITHM] [-dname NAME]
                    [-validity DAY_COUNT] [-keypass PASSWORD]
                    [-storetype STORE_TYPE] [-keystore URL]
                    [-storepass PASSWORD] [-provider PROVIDER_CLASS_NAME] [-v].
  -identitydb     NOT IMPLEMENTED YET.  Import JDK1.1 Identity Database.
                    [-file FILE] [-storetype STORE_TYPE] [-keystore URL]
                    [-storepass PASSWORD] [-provider PROVIDER_CLASS_NAME] [-v].
  -certreq        Issue a Certificate Signing Request (CSR).
                    [-alias ALIAS] [-sigalg ALGORITHM] [-file FILE]
                    [-keypass PASSWORD] [-storetype STORE_TYPE] [-keystore URL]
                    [-storepass PASSWORD] [-provider PROVIDER_CLASS_NAME] [-v]
                    [-attributes].
  -export         Export a Certificate from a key store.
                    [-alias ALIAS] [-file FILE] [-storetype STORE_TYPE]
                    [-keystore URL] [-storepass PASSWORD]
                    [-provider PROVIDER_CLASS_NAME] [-rfc] [-v].
  -list           Print one or all Certificates in a key store to STDOUT.
                    [-alias ALIAS] [-storetype STORE_TYPE] [-keystore URL]
                    [-storepass PASSWORD] [-provider PROVIDER_CLASS_NAME] 
                    [-rfc] [-v].
  -printcert      Print a human-readable form of a Certificate in a FILE.
                    [-file FILE] [-v].
  -keyclone       Clone a Key Entry in a key store.
                    [-alias ALIAS] [-dest ALIAS] [-keypass PASSWORD]
                    [-new PASSWORD] [-storetype STORE_TYPE] [-keystore URL]
                    [-storepass PASSWORD] [-provider PROVIDER_CLASS_NAME] [-v].
  -storepasswd    Change the password protecting a key store.
                    [-new PASSWORD] [-storetype STORE_TYPE] [-keystore URL]
                    [-storepass PASSWORD] [-provider PROVIDER_CLASS_NAME] [-v].
  -keypasswd      Change the password protecting a Key Entry in a key store.
                    [-alias ALIAS] [-keypass PASSWORD] [-new PASSWORD]
                    [-storetype STORE_TYPE] [-keystore URL]
                    [-storepass PASSWORD] [-provider PROVIDER_CLASS_NAME] [-v].
  -delete         Delete a Key Entry or a Trusted Certificate from a key store.
                    [-alias ALIAS] [-storetype STORE_TYPE] [-keystore URL]
                    [-storepass PASSWORD] [-provider PROVIDER_CLASS_NAME] [-v].
  -cacert         Import a CA's Trusted Certificate.
                    [-file FILE] [-storetype STORE_TYPE] [-keystore URL]
                    [-storepass PASSWORD] [-provider PROVIDER_CLASS_NAME] [-v].

Standard options:
      -help       print this help, then exit
      -version    print version number, then exit
  -JOPTION        pass argument to the Java runtime

Please report bugs at http://www.gnu.org/software/classpath/bugs.html

出了什么问题,我该如何解决?我是 运行 Linux 薄荷 17.2 肉桂。

问题是有两个同名的不同工具"keytool"。

一个随 linux 发行版一起提供,当您在终端中编写 "keytool" 命令时默认使用它。当你运行man keytool你可以看到描述:

NAME
       gkeytool - Manage private keys and public certificate

但出于您的目的,需要使用 Java 安装附带的 keytool – 您必须找到 Java 目录,对我来说它在 /opt/java/jdk1.8.0_65/bin .当你在这里时,只是 运行 相同的命令,但在命令的开头使用 ./keytool 而不是 keytool ,e。 g.:

./keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v