{"id":42,"date":"2015-08-28T11:03:11","date_gmt":"2015-08-28T08:03:11","guid":{"rendered":"https:\/\/amsd.go.ro\/wordpress\/?p=42"},"modified":"2021-09-07T11:26:24","modified_gmt":"2021-09-07T08:26:24","slug":"the-most-common-java-keytool-keystore-commands","status":"publish","type":"post","link":"https:\/\/amsd.go.ro\/wordpress\/?p=42","title":{"rendered":"The Most Common Java Keytool Keystore Commands"},"content":{"rendered":"<div class=\"level1\">\n<p>Java Keytool is a key and certificate management utility. It allows users to manage their own public\/private key pairs and certificates. It also allows users to cache certificates. Java Keytool stores the keys and certificates in what is called a keystore. By default the Java keystore is implemented as a file. It protects private keys with a password. A Keytool keystore contains the private key and any certificates necessary to complete a chain of trust and establish the trustworthiness of the primary certificate.<\/p>\n<p>Each certificate in a Java keystore is associated with a unique alias. When creating a Java keystore you will first create the .jks file that will initially only contain the private key. You will then generate a CSR and have a certificate generated from it. Then you will import the certificate to the keystore including any root certificates. Java Keytool also several other functions that allow you to view the details of a certificate or list the certificates contained in a keystore or export a certificate.<\/p>\n<p>Below, we have listed the most common Java Keytool keystore commands and their usage.<\/p>\n<\/div>\n<div class=\"secedit editbutton_section editbutton_1\">&nbsp;<\/div>\n<h2 id=\"java_keytool_commands_for_creating_and_importing\" class=\"sectionedit2\">Java Keytool Commands for Creating and Importing<\/h2>\n<div class=\"level2\">\n<p>These commands allow you to generate a new Java Keytool keystore file, create a CSR, and import certificates. Any root or intermediate certificates will need to be imported before importing the primary certificate for your domain.<\/p>\n<ul>\n<li class=\"level1\">\n<div class=\"li\">Generate a Java keystore and key pair: <code>keytool -genkey -alias mydomain -keyalg RSA -keystore keystore.jks -keysize 2048<\/code><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Generate a certificate signing request (CSR) for an existing Java keystore: <code>keytool -certreq -alias mydomain -keystore keystore.jks -file mydomain.csr<\/code><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Import a root or intermediate CA certificate to an existing Java keystore: <code>keytool -import -trustcacerts -alias root -file Thawte.crt -keystore keystore.jks<\/code><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Import a signed primary certificate to an existing Java keystore: <code>keytool -import -trustcacerts -alias mydomain -file mydomain.crt -keystore keystore.jks<\/code><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Generate a keystore and self-signed certificate: <code>keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 360 -keysize 2048<\/code><\/div>\n<\/li>\n<\/ul>\n<\/div>\n<div class=\"secedit editbutton_section editbutton_2\">&nbsp;<\/div>\n<h2 id=\"java_keytool_commands_for_checking\" class=\"sectionedit3\">Java Keytool Commands for Checking<\/h2>\n<div class=\"level2\">\n<p>If you need to check the information within a certificate, or Java keystore, use these commands.<\/p>\n<ul>\n<li class=\"level1\">\n<div class=\"li\">Check a stand-alone certificate: <code>keytool -printcert -v -file mydomain.crt<\/code><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Check which certificates are in a Java keystore: <code>keytool -list -v -keystore keystore.jks<\/code><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Check a particular keystore entry using an alias: <code>keytool -list -v -keystore keystore.jks -alias mydomain<\/code><\/div>\n<\/li>\n<\/ul>\n<\/div>\n<div class=\"secedit editbutton_section editbutton_3\">&nbsp;<\/div>\n<h2 id=\"other_java_keytool_commands\" class=\"sectionedit4\">Other Java Keytool Commands<\/h2>\n<div class=\"level2\">\n<ul>\n<li class=\"level1\">\n<div class=\"li\">Delete a certificate from a Java Keytool keystore: <code>keytool -delete -alias mydomain -keystore keystore.jks <\/code><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Change a Java keystore password: <code>keytool -storepasswd -new new_storepass -keystore keystore.jks<\/code><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Export a certificate from a keystore: <code>keytool -export -alias mydomain -file mydomain.crt -keystore keystore.jks<\/code><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">List Trusted CA Certs: <code>keytool -list -v -keystore $JAVA_HOME\/jre\/lib\/security\/cacerts<\/code><\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Import New CA into Trusted Certs: <code>keytool -import -trustcacerts -file \/path\/to\/ca\/ca.pem -alias CA_ALIAS -keystore $JAVA_HOME\/jre\/lib\/security\/cacerts<\/code><\/div>\n<\/li>\n<\/ul>\n<p>For more information, check out the <a class=\"urlextern\" title=\"http:\/\/java.sun.com\/j2se\/1.5.0\/docs\/tooldocs\/solaris\/keytool.html\" href=\"http:\/\/java.sun.com\/j2se\/1.5.0\/docs\/tooldocs\/solaris\/keytool.html\" rel=\"nofollow\">Java Keytool documentation<\/a> or check out <a class=\"urlextern\" title=\"http:\/\/www.sslshopper.com\/tomcat-ssl-installation-instructions.html\" href=\"http:\/\/www.sslshopper.com\/tomcat-ssl-installation-instructions.html\" rel=\"nofollow\">Tomcat SSL Installation Instructions<\/a> which use Java Keytool.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Java Keytool is a key and certificate management utility. It allows users to manage their own public\/private key pairs and certificates. It also allows users to cache certificates. Java Keytool stores the keys and certificates in what is called a [&hellip;]<\/p>\n<div class=\"link-more\"><a href=\"https:\/\/amsd.go.ro\/wordpress\/?p=42#more-42\" class=\"more-link\">Continue reading &#10142; <span class=\"screen-reader-text\">The Most Common Java Keytool Keystore Commands<\/span><\/a><\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[17,10,12],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry","category-technology","tag-ps_33","tag-ps_32","tag-ps_17"],"_links":{"self":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=42"}],"version-history":[{"count":1,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/42\/revisions"}],"predecessor-version":[{"id":199,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/42\/revisions\/199"}],"wp:attachment":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}