SSOGEN / Free tools / Keytool commands: generator and cheat sheet
SSOGEN
Keytool commands: generator and cheat sheet
Pick a task and get the exact keytool commands for it, with what every flag does and the OpenSSL equivalent beside it. The generated command never contains a password.
keytool is the command-line key and certificate manager that ships with the JDK. Its commands create key pairs, import and export certificates and list what a keystore holds. The generator below writes the command for one task, in one line you can copy.
Generate a keytool command
The command omits -storepass, so keytool prompts for the password and nothing lands in your shell history. For scripts, the tool offers -storepass:env KS_PASS, which reads the password from an environment variable. Everything runs in your browser and nothing is sent.
Keytool commands for ten common tasks
Every command below was run with keytool 21.0.12 and OpenSSL 3.5.8. File names, aliases and the acme.example host are placeholders.
| Task | keytool command | OpenSSL equivalent | What it changes |
|---|---|---|---|
| List the entries of a keystore | keytool -list -v -keystore acme.p12 |
openssl pkcs12 -in acme.p12 -nokeys |
Nothing |
| Print a certificate file | keytool -printcert -file acme.pem |
openssl x509 -in acme.pem -noout -text |
Nothing |
| Import a trusted CA or server certificate | keytool -importcert -trustcacerts -alias acme-ca -file acme-ca.pem -keystore truststore.p12 |
None | Adds a trusted entry; creates the file if it is missing |
| Import the CA reply for a key pair | keytool -importcert -alias acme-app -file reply.pem -keystore acme.p12 |
openssl pkcs12 -export -inkey key.pem -in reply.pem -certfile ca.pem -name acme-app -out acme.p12 |
Replaces the key entry’s certificate with the signed chain |
| Export a certificate | keytool -exportcert -alias acme-app -keystore acme.p12 -rfc -file acme.pem |
openssl pkcs12 -in acme.p12 -nokeys -out acme.pem |
Writes a file; the keystore is unchanged |
| Generate a key pair (self-signed, PKCS12) | keytool -genkeypair -alias acme-app -keyalg RSA -keysize 2048 -validity 365 -dname "CN=app.acme.example, O=Acme" -ext "SAN=dns:app.acme.example" -keystore acme.p12 -storetype PKCS12 |
openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365 -subj "/CN=app.acme.example/O=Acme" -addext "subjectAltName=DNS:app.acme.example" |
Adds a private key entry |
| Generate a CSR | keytool -certreq -alias acme-app -keystore acme.p12 -file acme.csr |
openssl req -new -key key.pem -subj "/CN=app.acme.example/O=Acme" -out acme.csr |
Writes a file; the keystore is unchanged |
| Change the store password | keytool -storepasswd -keystore acme.p12 |
None in place; export again with openssl pkcs12 -export |
Re-protects the whole file |
| Convert JKS to PKCS12 | keytool -importkeystore -srckeystore old.jks -srcstoretype JKS -destkeystore new.p12 -deststoretype PKCS12 |
None: OpenSSL cannot read JKS | Writes a new file; the JKS file is unchanged |
| Delete an alias | keytool -delete -alias acme-ca -keystore truststore.p12 |
None | Removes the entry; keep a copy of the file first |
To read a certificate file in more detail, use the certificate decoder. To make the request that the CSR row writes, the CSR generator works in the browser; for a test key pair, use the self-signed certificate generator.
keytool cannot import a PEM private key. keytool -importcert on a key file fails with “Input not an X.509 certificate”. Build a PKCS12 file with openssl pkcs12 -export -inkey key.pem -in cert.pem -out bundle.p12, then run keytool -importkeystore with that file as the source.
List the Java cacerts store
Run keytool -list -cacerts to list the JDK default truststore. The -cacerts option stands in for -keystore and -storetype; keytool reports an error if you pass either one with it. The location and the default password differ by JDK build, so the cacerts explainer covers them.
What changes between JDK versions
Four differences decide whether a command from an older guide works.
- JDK 9 and later: PKCS12 is the default. New keystores use PKCS12 (JEP 229); existing JKS files are not changed and keytool still reads them.
- JDK 21: omitted values are not 2048 and 365.
-genkeypairwithout-keysizeor-validitycreates a 3,072-bit RSA key valid for 90 days. The generator writes both values out. - PKCS12:
-keypasswdis refused. keytool answers that-keypasswdis not supported with-storetype PKCS12. Use-storepasswd. - Old names still work.
-importand-exportare earlier names of-importcertand-exportcert; Oracle prefers the new ones.
Keytool errors you will hit
These are the messages the commands above produced, with the cause and the fix.
Failed to establish chain from reply. The CA reply has no issuer in the keystore. Import the issuing CA with-importcert -trustcacertsfirst, then the reply under the key entry’s alias.Keystore was tampered with, or password was incorrect. The password is wrong, or the file is not the store type keytool assumed. Check the password, then add-storetype.Alias <name> does not exist. The alias is misspelled or in another keystore. Run the list command first and copy the alias from its output.
A Java application that fails with PKIX path building failed has the matching problem at run time; the fix is on the PKIX path building failed page.
Questions people ask
How do I list certificates in a keystore with keytool?
Run keytool -list -v -keystore acme.p12. keytool asks for the keystore password, then prints each entry with its alias, type, owner, issuer, validity dates and fingerprints. Drop -v for one line per entry. Add -alias acme-app to show a single entry.
How do I import a certificate into the Keytool keystore?
Run keytool -importcert -trustcacerts -alias acme-ca -file acme-ca.pem -keystore truststore.p12. keytool prints the certificate and asks whether to trust it; answer yes only after you have checked the fingerprint. The alias must not already exist. Add -noprompt only in a script that has verified the file.
How do I print a certificate file with keytool?
Run keytool -printcert -file acme.pem. It reads a PEM or DER certificate file and prints the owner, issuer, serial number, validity dates, fingerprints and extensions. No keystore or password is needed because the command only reads the file.
How do I delete a certificate or alias from a keystore?
Run keytool -delete -alias acme-ca -keystore truststore.p12. The command removes the entry and writes the file at once, so copy the keystore first. If the alias is wrong, keytool reports that it does not exist. List the keystore to find the exact alias before you delete.
Why does keytool: command not found appear?
The shell cannot find keytool on its search path. keytool is installed with the JDK, in its bin directory. Run it by full path, or add that directory to PATH and open a new terminal. On Windows the same fault reads “not recognized as an internal or external command”.
Where to go next
To open a JKS or PKCS12 file without a terminal, the Java keystore viewer lists its entries in the browser.
Sources, all read 2026-11-17: Oracle, keytool reference, JDK 21; OpenJDK, JEP 229: Create PKCS12 Keystores by Default; OpenSSL 3.5, openssl-pkcs12.