Get a Pentest and security assessment of your IT network.

Cyber Security

Secure HTTPS Key Generation

TL;DR

This guide shows you how to create a strong private key for your website’s HTTPS security. We’ll cover using OpenSSL, storing it safely, and important considerations.

Generating Your Private Key

  1. Choose a Strong Algorithm: RSA is common, but ECC (Elliptic Curve Cryptography) offers better security for the same key length. For new keys, consider ECDSA with curves like secp384r1 or secp521.
  2. Use OpenSSL: OpenSSL is a powerful command-line tool available on most systems. If it’s not installed, you’ll need to install it (e.g., sudo apt-get install openssl on Debian/Ubuntu).
  3. Generate the Key (RSA Example): This creates a 2048-bit RSA key.
    openssl genrsa -out yourdomain.key 2048
  4. Generate the Key (ECC Example): This creates an ECDSA key using the secp384r1 curve.
    openssl ecparam -name prime256v1 -genkey -noout -out yourdomain.key
  5. Secure Key Permissions: Immediately after generation, restrict access to the key file. Only the user running your web server should be able to read it.
    chmod 400 yourdomain.key

Storing Your Private Key

  1. Never Store in Web Root: Absolutely avoid placing the key file within your website’s document root (e.g., /var/www/html). This is a major security risk.
  2. Dedicated Directory: Create a dedicated, restricted directory for keys.
    mkdir /etc/ssl/private

    Move the key file there:

    mv yourdomain.key /etc/ssl/private/
  3. File System Permissions: Ensure only the web server user can read the key.
    chown www-data:www-data /etc/ssl/private/yourdomain.key

    (Replace www-data with your web server’s user.)

  4. Backups: Create secure backups of the key, stored offline and encrypted. Consider a hardware security module (HSM) for critical applications.

Important Considerations

  • Key Length: For RSA, 2048 bits is the minimum recommended length. 3072 or 4096 bits are stronger. ECC keys of equivalent security require shorter lengths (e.g., secp384r1).
  • Passphrase Protection: You can encrypt the private key with a passphrase during generation.
    openssl genrsa -des3 -out yourdomain.key 2048

    You’ll be prompted for a passphrase. *However*, automating server setup becomes harder, and you need to securely manage the passphrase.

  • Regular Rotation: Periodically rotate your private keys (e.g., every year or after a security incident).
  • Cyber security Best Practices: Keep your OpenSSL version up-to-date to patch vulnerabilities. Regularly audit server configurations and logs.
Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation