Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate Keystore generation using the java keystore tool? w/o user interaction

Tags:

java

keystore

I am trying to automate keystore generation using the Java keystore tool. The command I am using is :

keytool -keystore keystore -alias jetty -genkey -keyalg RSA 

But after this command, user is required to enter certain inputs as follows:

Enter keystore password:  password What is your first and last name?   [Unknown]:  jetty.mortbay.org   What is the name of your organizational unit?   [Unknown]:  Jetty   What is the name of your organization?   [Unknown]:  Mort Bay Consulting Pty. Ltd.   What is the name of your City or Locality?   [Unknown]:   What is the name of your State or Province?   [Unknown]:   What is the two-letter country code for this unit?   [Unknown]:   Is CN=jetty.mortbay.org, OU=Jetty, O=Mort Bay Consulting Pty. Ltd.,   L=Unknown, ST=Unknown, C=Unknown correct?   [no]:  yes    Enter key password for <jetty>   (RETURN if same as keystore password):  password   

Instead of the user entering these values , is there any way of providing these values without user interaction ,either within the command or through a script?

Thanks

like image 506
r3ap3r Avatar asked Nov 27 '12 05:11

r3ap3r


People also ask

What is used to generate a keystore and key?

Use the standard JDK keytool utility to generate and load a new key and a self-signed certificate. When prompted, supply the certificate and password information. Doing so protects the keystore file and the keys within in the file.

What is keystore tool?

keytool is a key and certificate management utility. It allows users to administer their own public/private key pairs and associated certificates for use in self-authentication (where the user authenticates himself/herself to other users/services) or data integrity and authentication services, using digital signatures.


1 Answers

Try this:

keytool -genkey -noprompt \  -alias alias1 \  -dname "CN=mqttserver.ibm.com, OU=ID, O=IBM, L=Hursley, S=Hants, C=GB" \  -keystore keystore \  -storepass password \  -keypass password 
like image 71
Evgeniy Dorofeev Avatar answered Oct 05 '22 13:10

Evgeniy Dorofeev