Setting up a Certificate Authority (CA) server with intermediate CA servers is a best practice for public key infrastructure (PKI) deployments. This setup increases security by keeping the root CA offline and using intermediate CAs for day-to-day certificate issuance.
Below is a step-by-step guide using OpenSSL on Linux, which is a common and free tool for this purpose. The process is similar for Windows (using tools like AD CS), but the commands and file locations will differ.
1. Directory Structure
Create a directory structure for the root and intermediate CAs:
mkdir -p ~/ca/rootCA/{certs,crl,newcerts,private}
mkdir -p ~/ca/intermediateCA/{certs,crl,csr,newcerts,private}
chmod 700 ~/ca/rootCA/private ~/ca/intermediateCA/private
touch ~/ca/rootCA/index.txt ~/ca/intermediateCA/index.txt
echo 1000 > ~/ca/rootCA/serial
echo 1000 > ~/ca/intermediateCA/serial
echo 1000 > ~/ca/intermediateCA/crlnumber
2. Create OpenSSL Config Files
Copy the default OpenSSL config file and edit for root and intermediate CAs:
cp /etc/ssl/openssl.cnf ~/ca/rootCA/openssl.cnf
cp /etc/ssl/openssl.cnf ~/ca/intermediateCA/openssl.cnf
Edit the files to set the correct directories and policies. (Refer to OpenSSL CA Howto for detailed config examples.)
3. Create the Root CA
a. Generate Root CA Private Key
openssl genrsa -aes256 -out ~/ca/rootCA/private/ca.key.pem 4096
chmod 400 ~/ca/rootCA/private/ca.key.pem
b. Create Root CA Certificate
openssl req -config ~/ca/rootCA/openssl.cnf \
-key ~/ca/rootCA/private/ca.key.pem \
-new -x509 -days 7300 -sha256 -extensions v3_ca \
-out ~/ca/rootCA/certs/ca.cert.pem
chmod 444 ~/ca/rootCA/certs/ca.cert.pem
4. Create the Intermediate CA
a. Generate Intermediate CA Private Key
openssl genrsa -aes256 -out ~/ca/intermediateCA/private/intermediate.key.pem 4096
chmod 400 ~/ca/intermediateCA/private/intermediate.key.pem
b. Create Intermediate CA CSR
openssl req -config ~/ca/intermediateCA/openssl.cnf \
-new -sha256 \
-key ~/ca/intermediateCA/private/intermediate.key.pem \
-out ~/ca/intermediateCA/csr/intermediate.csr.pem
c. Sign Intermediate CA CSR with Root CA
openssl ca -config ~/ca/rootCA/openssl.cnf \
-extensions v3_intermediate_ca \
-days 3650 -notext -md sha256 \
-in ~/ca/intermediateCA/csr/intermediate.csr.pem \
-out ~/ca/intermediateCA/certs/intermediate.cert.pem
chmod 444 ~/ca/intermediateCA/certs/intermediate.cert.pem
5. Create the CA Chain File
cat ~/ca/intermediateCA/certs/intermediate.cert.pem \
~/ca/rootCA/certs/ca.cert.pem > ~/ca/intermediateCA/certs/ca-chain.cert.pem
chmod 444 ~/ca/intermediateCA/certs/ca-chain.cert.pem
6. Use the Intermediate CA to Issue Certificates
Now, use the intermediate CA to sign CSRs for servers, users, etc.
openssl ca -config ~/ca/intermediateCA/openssl.cnf \
-extensions server_cert -days 375 -notext -md sha256 \
-in server.csr.pem \
-out server.cert.pem
7. Security Best Practices
- Keep the root CA offline (only bring it online to sign intermediate CAs or revoke them).
- Use strong passphrases and secure storage for private keys.
- Regularly backup your CA directories and keys.
- Use CRLs or OCSP for revocation.
References & Further Reading
If you need a Windows/AD CS-specific guide or a more automated/scripted approach, let me know!