How to Use Java Keytool Command

Most Common Commands

List Certificates in Keystore

What

Command

Summary View

keytool -list -keystore keystore.jks -storepass password

Linux: keytool -list -keystore keystore.jks -storepass password | grep "string" 

Cmd: keytool -list -keystore keystore.jks -storepass password | findstr "string" 

Pwsh: keytool -list -keystore keystore.jks -storepass password | Select-String "string" 

Detail View keytool -list -v -keystore keystore.jks -storepass password
Specific Certificate keytool -list -keystore keystore.jks -storepass password -alias root
Specific File keytool -printcert -file kafka-prod-cacert.crt

Export/Import

What Command
Export keytool -export -alias root -file kafka-nonprod-cacart.crt -keystore keystore.jks-storepass password
Delete keytool -delete -alias root -keystore keystore.jks -storepass password
Import keytool -import -trustcacerts -alias kafka-nonprod-cacert -file kafka-nonprod-cacart.crt -keystore keystore.jks -storepass password -noprompt

References