Skip to content

Instantly share code, notes, and snippets.

@thesuhu
Created November 16, 2024 19:15
Show Gist options
  • Save thesuhu/69daab7a7bf50e1fcf77d39784abf6e5 to your computer and use it in GitHub Desktop.
Save thesuhu/69daab7a7bf50e1fcf77d39784abf6e5 to your computer and use it in GitHub Desktop.
How to Generate a Self-Signed Certificate Using OpenSSL

How to Generate a Self-Signed Certificate Using OpenSSL

# Step 1: Generate a Private Key
openssl genrsa -out myprivate.key 2048

# Step 2: Create a Certificate Signing Request (CSR)
openssl req -new -key myprivate.key -out myrequest.csr

# Step 3: Generate a Self-Signed Certificate
openssl x509 -req -days 365 -in myrequest.csr -signkey myprivate.key -out mycertificate.crt

# Step 4: View the Self-Signed Certificate
openssl x509 -in mycertificate.crt -text -noout

Explanation:

  1. Generate a Private Key: Creates a 2048-bit RSA private key.
  2. Create a Certificate Signing Request (CSR): Prompts for information such as Country, State, Organization, etc.
  3. Generate a Self-Signed Certificate: Signs the certificate using the private key and sets its validity for 365 days.
  4. View the Self-Signed Certificate: Displays the certificate details in a readable format.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment