Created
September 22, 2023 09:31
-
-
Save dahoba/bcaab178d8f4782cbd323076b00d52d9 to your computer and use it in GitHub Desktop.
Shell script to generate postgresql SSL (RSA 4096)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
set -e | |
export MSYS_NO_PATHCONV=1 | |
#https://www.postgresql.org/docs/12/ssl-tcp.html#SSL-CERTIFICATE-CREATION | |
# echo "clean old files" | |
# rm -rf postgresql | |
echo "generating new certificates" | |
mkdir -p ./postgresql-ssl | |
cd ./postgresql-ssl | |
# root | |
openssl req -new -newkey rsa:4096 -nodes -text -out root.csr \ | |
-keyout root.key -subj "/CN=db.example.com" | |
chmod og-rwx root.key | |
openssl x509 -req -in root.csr -text -days 3650 -sha256 \ | |
-extfile ../etc_ssl_openssl.cnf -extensions v3_ca \ | |
-signkey root.key -out root.crt | |
# intermediate | |
openssl req -new -nodes -text -out intermediate.csr \ | |
-keyout intermediate.key -subj "/CN=db.example.com" | |
chmod og-rwx intermediate.key | |
openssl x509 -req -in intermediate.csr -text -days 1825 -sha256 \ | |
-extfile ../etc_ssl_openssl.cnf -extensions v3_ca \ | |
-CA root.crt -CAkey root.key -CAcreateserial \ | |
-out intermediate.crt | |
# leaf | |
openssl req -new -nodes -text -out server.csr \ | |
-keyout server.key -subj "/CN=db.example.com" | |
chmod og-rwx server.key | |
openssl x509 -req -in server.csr -text -days 1825 -sha256 \ | |
-CA intermediate.crt -CAkey intermediate.key -CAcreateserial \ | |
-out server.crt | |
# echo "server.key, server.crt, intermediate.crt" |
Author
dahoba
commented
Sep 22, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment