How to Build a Private CA with OpenSSL: Step‑by‑Step Guide

This article explains why encrypting network traffic is essential, introduces OpenSSL’s cryptographic components, and provides a detailed, command‑line tutorial for creating a private Certificate Authority, issuing certificates, and handling revocation within a LAN environment.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Build a Private CA with OpenSSL: Step‑by‑Step Guide

Preface

With the rapid growth of the Internet, network communication has become the main way to transmit information, yet most data is still sent in plaintext. Without encryption mechanisms, sensitive information can be leaked, causing severe losses. OpenSSL fills this gap as a powerful open‑source suite that includes libcrypto (cryptographic library), libssl (SSL protocol implementation), and the openssl command‑line tool. It is widely used for data‑in‑transit encryption and can also build a private CA within a LAN.

Data Encryption and Decryption Process

Encryption must achieve confidentiality, integrity, authentication, and key exchange.

Encryption types and functions:
One‑way encryption: generate data fingerprint for integrity verification
Symmetric encryption: protect data confidentiality
Public‑key encryption: use the peer’s public key for key exchange
Private‑key encryption: use own private key for authentication

Because public keys transmitted over the network cannot be trusted, a trusted third‑party (CA) is required.

CA Workflow

# A and B each decrypt the other's certificate with the CA’s public key to complete authentication

Since commercial CAs are expensive, enterprises can build their own private CA within a LAN when external communication is not required.

Implementing the CA

OpenSSL can build a private CA suitable for small‑to‑medium enterprises; larger organizations may consider OpenCA.

Establish CA Server – Generate Keys

Command details:
umask 077   # ensure key files are not readable/writable by others
-out /path/to/somefile   # specify output location for the key
2048   # key length, can be customized
# openssl rsa -in private/cakey.pem -pubout -text   # extract public key

Self‑Signed Certificate

Command details:
req -new   # generate certificate signing request
-key /path/to/keyfile   # specify private key file
-out /path/to/somefile   # specify output certificate file
-x509   # generate self‑signed certificate
-days n   # validity period in days
# Country Name (2 letter code) [XX]: CN
# State or Province Name (full name) []: Shandong
# Locality Name (eg, city) [Default City]: Qingdao
# Organization Name (eg, company) [Default Company Ltd]: Scholar
# Organizational Unit Name (eg, section) []: Tech
# Common Name (eg, your name or your server's hostname) []: ca.scholar.com
# Email Address []: [email protected]

These defaults can be changed by editing /etc/pki/tls/openssl.cnf.

Initialize Working Environment

index.txt   # certificate database
serial   # file storing the next certificate serial number
echo 01 > serial   # set initial serial number

Client Requests Certificate

Generate client key and CSR, then send the request to the CA.

Generate CSR:

# A challenge password []:   # optional password to protect the request
# An optional company name []:

Place the CSR in a directory on the CA server.

CA signs the certificate and returns it to the client.

Client receives the signed certificate.

Certificate Revocation

Client obtains the certificate serial number.

CA verifies the serial and subject against index.txt, then revokes the certificate.

CA generates a revocation entry and updates the CRL.

CA updates the certificate revocation list.

# If needed, view the CRL file:
openssl crl -in /path/to/crlfile.crl -noout -text

The certificate is now revoked and can be re‑issued.

The end

This concludes the step‑by‑step process of building a private CA with OpenSSL. Test the results yourself; this guide is for personal learning and may contain omissions.

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.

encryptionOpenSSLTLSCertificate AuthorityPrivate CA
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.