Created
September 2, 2025 13:38
-
-
Save onequbit/f81e42285fc880c79aaa0216af7fc76b to your computer and use it in GitHub Desktop.
create self-signed certificates
This file contains hidden or 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
| #!/bin/bash | |
| # This script generates a self-signed SSL certificate if one doesn't already exist. | |
| CERT_DIR="./certs" | |
| CERT_KEY_FILE="$CERT_DIR/localhost.key" | |
| CERT_PUBLIC_FILE="$CERT_DIR/localhost.crt" | |
| CERT_DOMAIN="localhost" | |
| CERT_STATE="Spira" | |
| CERT_LOCALITY="Besaid" | |
| CERT_ORGANIZATION="Aurochs" | |
| # Create the certificate directory if it doesn't exist | |
| if [ ! -d "$CERT_DIR" ]; then | |
| echo "Creating certificate directory: $CERT_DIR" | |
| mkdir -p "$CERT_DIR" | |
| fi | |
| # Check if the certificate and key files already exist | |
| if [ -f "$CERT_KEY_FILE" ] && [ -f "$CERT_PUBLIC_FILE" ]; then | |
| echo "SSL certificate and key already exist. Skipping generation." | |
| else | |
| echo "Generating self-signed SSL certificate for $CERT_DOMAIN..." | |
| openssl req -x509 -nodes -newkey rsa:2048 -keyout "$CERT_KEY_FILE" -out "$CERT_PUBLIC_FILE" -days 365 \ | |
| -subj "/C=US/ST=$CERT_STATE/L=$CERT_LOCALITY/O=$CERT_ORGANIZATION/CN=$CERT_DOMAIN" | |
| echo "Certificate and key generated successfully." | |
| fi | |
| # Set appropriate permissions for the key file | |
| chmod 600 "$CERT_KEY_FILE" | |
| echo "Script finished." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment