Last active
August 25, 2021 22:14
-
-
Save mike10004/5304d8ea156006d2522e95217eefeded to your computer and use it in GitHub Desktop.
Copy certificates somewhere else on renewal by letsencrypt certbot
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
#!/bin/bash | |
# IMPORTANT: set TARGET and DEST_DIR according to your use case | |
TARGET="example.com" | |
DEST_DIR="/etc/ssl/private/active" | |
set -e | |
echo "Renewal hook running to copy certificate and private key to appropriate directory..." | |
echo "RENEWED_DOMAINS=$RENEWED_DOMAINS" | |
echo "RENEWED_LINEAGE=$RENEWED_LINEAGE" | |
for DOMAIN in $RENEWED_DOMAINS ; do | |
if [ "$DOMAIN" == "$TARGET" ] ; then | |
find -L "/etc/letsencrypt/live/$TARGET" -type f -name "*.pem" | xargs -r cp -v --target "$DEST_DIR" | |
fi | |
done | |
chmod 0640 "$DEST_DIR/privkey.pem" | |
chown :ssl-cert "$DEST_DIR/privkey.pem" | |
# Consider restarting the webserver that reads the certificate and private key | |
echo "Done copying certificates and private key" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment