As @sastorsl said, if you are worried about putting your password in clear text in your command or script (and you should), you should put your password in a secure file (with 0400 permissions, in Linux) or in an environment variable.
Now keytool
does have a similar construct to openssl
's file:<filename>
, if your password is in a file:
keytool <commands and options> -storepass:file <pass_file>
If your password is in an environment variable:
keytool <commands and options> -storepass:env <pass_var>
Disclaimer: I have tested the -storepass:file
option in Bash (not in Windows), but the documentation does not seem to have any difference according to the OS.
From the Oracle keytool doc:
-storepass [:env | :file ] argument
The password that is used to protect the integrity of the keystore.
If the modifier env
or file
isn’t specified, then the password has the value
argument, which must contain at least six characters. Otherwise, the password is retrieved as follows:
env
: Retrieve the password from the environment variable named argument
.
file
: Retrieve the password from the file named argument.
Note: All other options that require passwords, such as -keypass
, -srckeypass
, -destkeypass
, -srcstorepass
, and -deststorepass
, accept the env
and file
modifiers. Remember to separate the password option and the modifier with a colon (:).