Skip to content

Instantly share code, notes, and snippets.

@miki725
Last active October 4, 2015 07:08
Show Gist options
  • Save miki725/2598762 to your computer and use it in GitHub Desktop.
Save miki725/2598762 to your computer and use it in GitHub Desktop.
Creating self-signed ssl certificates for nginx
#! /bin/bash
# Steps are taken from http://bit.ly/12HLd0
# To use, sudo priviledges are need (to copy the certificate
# and key to /etc/ssl/)
#
# The script has one required argument - the name of the certificate
# to be generated. Once the script starts running, just follow
# on-screen instructions.
if [[ $1 != "" ]]; then
# generate key
openssl genrsa -des3 -out $1.key 1024
# generate certificate signing request
openssl req -new -key $1.key -out $1.csr
# copy the key so that the password can be removed
cp $1.key $1.key.orig
# remove the password from the key
openssl rsa -in $1.key.orig -out $1.key
# generta the actual certificate
openssl x509 -req -days 365 -in $1.csr -signkey $1.key -out $1.crt
# clean up
rm $1.key.orig $1.csr
# move to /etc/ssl/
mv $1.crt /etc/ssl/certs/
mv $1.key /etc/ssl/private/
else
echo "Usage: $0 name";
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment