Mastering keytool on CentOS 7: Generate Keystores, CSRs, and Manage Certificates

This guide walks Java developers through essential keytool commands on CentOS 7, covering keystore creation, key pair generation, CSR creation, certificate import, listing entries, and exporting certificates to simplify SSL/TLS handling.

Ops Development & AI Practice
Ops Development & AI Practice
Ops Development & AI Practice
Mastering keytool on CentOS 7: Generate Keystores, CSRs, and Manage Certificates

keytool is a security utility bundled with the Java Development Kit (JDK) for managing keys and certificates. The following examples demonstrate its basic usage on CentOS 7.

Generate a keystore and key pair

Use the command below to create a new keystore file mykeystore.jks and a key pair named mykey with the RSA algorithm (2048‑bit) that is valid for 365 days.

keytool -genkeypair -alias mykey -keyalg RSA -keysize 2048 -keystore mykeystore.jks -validity 365

Generate a Certificate Signing Request (CSR)

When a certificate from a Certificate Authority (CA) is required, generate a CSR from the existing keystore entry:

keytool -certreq -alias mykey -file mycsr.csr -keystore mykeystore.jks

Import a certificate or certificate chain

After obtaining a signed certificate (e.g., mycertificate.crt), import it into the keystore and associate it with the alias:

keytool -importcert -alias mykey -file mycertificate.crt -keystore mykeystore.jks

List keystore contents

To view all entries stored in the keystore:

keytool -list -keystore mykeystore.jks

Export a certificate

Export the certificate linked to an alias to a file for distribution or further use:

keytool -exportcert -alias mykey -file mycertificate.crt -keystore mykeystore.jks

These commands cover the essential operations developers need when handling SSL/TLS certificates or interacting with Java applications on Linux.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaLinuxSSLcertificate-managementkeytool
Ops Development & AI Practice
Written by

Ops Development & AI Practice

DevSecOps engineer sharing experiences and insights on AI, Web3, and Claude code development. Aims to help solve technical challenges, improve development efficiency, and grow through community interaction. Feel free to comment and discuss.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.