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.
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 365Generate 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.jksImport 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.jksList keystore contents
To view all entries stored in the keystore:
keytool -list -keystore mykeystore.jksExport 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.jksThese commands cover the essential operations developers need when handling SSL/TLS certificates or interacting with Java applications on Linux.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
