Skip to content

Instantly share code, notes, and snippets.

@thbkrkr
Created April 7, 2015 16:15
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save thbkrkr/aa16435cb6c183e55a33 to your computer and use it in GitHub Desktop.
Save thbkrkr/aa16435cb6c183e55a33 to your computer and use it in GitHub Desktop.
Generate Self-Signed SSL Certificate without prompt
# Generate a passphrase
openssl rand -base64 48 > passphrase.txt
# Generate a Private Key
openssl genrsa -aes128 -passout file:passphrase.txt -out server.key 2048
# Generate a CSR (Certificate Signing Request)
openssl req -new -passin file:passphrase.txt -key server.key -out server.csr \
-subj "/C=FR/O=krkr/OU=Domain Control Validated/CN=*.krkr.io"
# Remove Passphrase from Key
cp server.key server.key.org
openssl rsa -in server.key.org -passin file:passphrase.txt -out server.key
# Generating a Self-Signed Certificate for 100 years
openssl x509 -req -days 36500 -in server.csr -signkey server.key -out server.crt
mv server.crt ssl.crt
mv server.key ssl.key
@drexlma
Copy link

drexlma commented Aug 19, 2019

nice

@Shahaed
Copy link

Shahaed commented Jul 26, 2020

nice nice

@gilacost
Copy link

nice nice nice

@dinvlad
Copy link

dinvlad commented Nov 14, 2020

nicenicenice

@dvolozhinok
Copy link

Very nice code, life saving!

Please mention, that to use with mini_httpd (if you need to display small amount of static pages — it's great solution) you need to do this after:

cat ssl.key >> ssl.crt
mv ssl.crt ssl.pem

@janfrederik
Copy link

Works in one single command for me:

openssl req -x509 -newkey rsa:4096 -nodes -out server.crt -keyout server.key -days 365 -subj "/C=FR/O=krkr/OU=Domain Control Validated/CN=*.krkr.io"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment