Skip to content

Instantly share code, notes, and snippets.

@m13253
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save m13253/fe76237a5dd249630033 to your computer and use it in GitHub Desktop.

Select an option

Save m13253/fe76237a5dd249630033 to your computer and use it in GitHub Desktop.
Generate a self-signed SSL certificate for web server
#!/bin/bash
set -e
outpemfile="${1:-cert.pem}"
tmpprefix="/tmp/gensslcert-$$"
openssl genrsa -des3 -out "$tmpprefix.key" 2048
openssl req -new -key "$tmpprefix.key" -out "$tmpprefix.csr"
openssl rsa -in "$tmpprefix.key" -out "$outpemfile"
rm -f "$tmpprefix.key"
openssl x509 -req -days 365 -in "$tmpprefix.csr" -signkey "$outpemfile" -out "$tmpprefix.crt"
cat "$tmpprefix.crt" >> "$outpemfile"
set +e
chmod 600 "$outpemfile"
rm -f "$tmpprefix.crt" "$tmpprefix.csr"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment