Skip to content

Instantly share code, notes, and snippets.

@matr1xp
Created September 5, 2023 10:11
Show Gist options
  • Save matr1xp/425df32c4ac233a1f2b542711256782e to your computer and use it in GitHub Desktop.
Save matr1xp/425df32c4ac233a1f2b542711256782e to your computer and use it in GitHub Desktop.
Create a self-signed certificate (localhost)
mkdir openssl && cd openssl
openssl req -x509 \
-sha256 -days 356 \
-nodes \
-newkey rsa:2048 \
-subj "/CN=localhost/C=AU/L=Location" \
-keyout rootCA.key -out rootCA.crt
openssl genrsa -out server.key 2048
cat > csr.conf <<EOF
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn
[ dn ]
C = AU
ST = State
L = Location
O = Organization
OU = Organizational Unit
CN = localhost
[ req_ext ]
subjectAltName = @alt_names
[ alt_names ]
DNS.1 = localhost
IP.1 = 127.0.0.1
EOF
--
openssl req -new -key server.key -out server.csr -config csr.conf
cat > cert.conf <<EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = demo.mlopshub.com
EOF
--
openssl x509 -req \
-in server.csr \
-CA rootCA.crt -CAkey rootCA.key \
-CAcreateserial -out server.crt \
-days 365 \
-sha256 -extfile cert.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment