Getting StartedSSL Certificates

SSL Certificates for Local Development

To create a localhost.crt and localhost.key in the current directory, follow these steps:

Generating SSL Certificates for Local Development

Prerequisites

Ensure you have OpenSSL installed on your system. OpenSSL is typically pre-installed on macOS or Linux. You can verify the installation by running:

bash
openssl version

If not installed, follow the instructions for your operating system to install OpenSSL.

Step-by-Step Guide

  1. Navigate to the desired directory:
    Open your terminal and navigate to the directory where you want to create the SSL certificates:
    bash
    cd /path/to/your/directory
    
  2. Generate a private key:
    Run the following command to generate a private key named localhost.key:
    bash
    openssl genrsa -out localhost.key 2048
    
  3. Create a certificate signing request (CSR):
    Use the private key to create a CSR. This step will prompt you to enter information about your organization. You can leave most fields blank, but ensure the Common Name (CN) is set to localhost:
    bash
    openssl req -new -key localhost.key -out localhost.csr
    
  4. Generate the SSL certificate:
    Create a self-signed SSL certificate named localhost.crt using the CSR and the private key. The certificate will be valid for 365 days:
    bash
    openssl x509 -req -days 365 -in localhost.csr -signkey localhost.key -out localhost.crt
    
  5. Clean up:
    You can remove the CSR file as it is no longer needed:
    bash
    rm localhost.csr
    

Summary of Commands

bash
cd /path/to/your/directory
openssl genrsa -out localhost.key 2048
openssl req -new -key localhost.key -out localhost.csr
openssl x509 -req -days 365 -in localhost.csr -signkey localhost.key -out localhost.crt
rm localhost.csr

Using the Certificates

You can now use localhost.crt and localhost.key to serve your development environment over HTTPS.