Java keytool useful commands

Here are some useful commands when manipulating Java keystores. (I will update this post from time to time)

(default keystore password: changeit)

Import a certficate into a Java keystore

keytool -import -keystore /jre/lib/security/cacerts -file mycertificate.der

Import a list of certificates into a Java keystore

#!/bin/bash

for file in /app/certs/* 
do
    if [[ -f $file ]]; then
        keytool -noprompt -storepass changeit -import -keystore $JAVA_HOME/jre/lib/security/cacerts -file $file -alias $file
    fi
done

List the certificates of a keystore in a file report.txt

keytool -list -v -keystore /jre/lib/security/cacerts > report.txt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s