Dobzinski's project for Let's Encrypt server to auto deploy of certs.
- Non database required!
- Apache + Php + Json
- Clients using Shell script
- Certificates Server will need aprove clients by symmetric keys
- jQuery 3.3.1 + Popper 1.14.7
- Font Awesome 4.7.0
- Bootstrap 4.3.1
- Linux CentOS/Debian
- Certbot
- OpenSSL
- Apache 2 + SSL
- Php 5 or higher
- Shell script (curl, md5sum, file, cut, tar, others)
- Linux
- Shell script (curl, md5sum, file, cut, tar, others)
- OpenSSL
CentOS 7:
# yum install certbot openssl httpd mod_ssl php git
# systemctl enable httpd.service
# systemctl start httpd.service
Debian 10:
# apt-get install certbot openssl apache2 php git
# a2enmod ssl
# a2ensite default-ssl
# service apache2 reload
Dot not use HTTP (Port 80), remember you will transfer keys from client to server, and will get Letsencrypt certificates Public and Private from this server. Insert those lines to Apache for redirect all requests to HTTPS (Port 443)
[...]
# Redirect to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
Notes:
- Install mod_rewrite, and insert lines on "httpd.conf" (CentOS) or "000-default.conf" (Debian) to redirect
- For Debian, Use "a2enmod rewrite" to enable mod_rewrite
- For CentOS, check the Firewall and SELinux
# certbot certonly --manual --preferred-challenges dns
TIP: Anwser the question for the domain *.domain.com (wildcard) and when see key value generated, WAIT! DO NOT PRESS ENTER KEY. Go to the external DNS and add the new TXT entry _acme-challenge.domain.com with the key value and insert "1" to TTL. Back to the terminal and press ENTER, you will see the sucess message!_
NOTE: if you using Debian, remember to change user "apache" to "www-data" on bellow commands lines...
# git clone https://github.com/dobzinski/dobz-letsencrypt
# chown -R apache. ./dobz-letsencrypt/server
# mv ./dobz-letsencrypt/server/letsencrypt /var/www/html/
# chown -R root. ./dobz-letsencrypt/server/cert
# chown -R apache. ./dobz-letsencrypt/server/cert/certificate
# chown -R apache. ./dobz-letsencrypt/server/cert/client
# chmod +x ./dobz-letsencrypt/server/cert/letsencrypt.sh
# mv ./dobz-letsencrypt/server/cert /opt/
# vi /var/www/html/letsencrypt/config.php
Customize: days left to alert, date/time format, theme, language ...
Edit the script "letsencrypt.sh" and change the "LIST" Array.
# vi /opt/cert/letsencrypt.sh
[...]
LIST=("domain1.com" "domain2.com")
Add the script on root cron
# contrab -e
0 21 * * * /opt/cert/letsencrypt.sh
Or use the crontab file
# vi /etc/crontab (add on last line)
0 21 * * * root /opt/cert/letsencrypt.sh
Check the requirements, but will maybe only need OpenSSL
Back to root path when was run "git clone"
# scp -r ./dobz-letsencrypt/client/agent {USER}@{CLIENT}:/tmp/
# mv /tmp/agent /opt/
# chown -R root. /opt/agent
# chmod +x /opt/agent/check.sh
# chmod +x /opt/agent/update.sh
# cd /opt/agent
# vi check.sh
# vi update.sh
# vi update.sh
Go to last lines and insert the command between lines...
# RUN COMMANDS
{INSERT YOUR COMMANDS HER}
# END COMMANDS
Examples:
- Apache/Ngix:
# /bin/systemctl restart httpd.service >/dev/null 2>&1
# /bin/systemctl reload nginx.service >/dev/null 2>&1
# /usr/bin/killall -9 nginx && /sbin/service nginx start >/dev/null 2>&1
# /etc/init.d/httpd restart >/dev/null 2>&1
- BIGIP F5 (First you need to uncomment BIGIP VARS):
# /usr/bin/tmsh install /sys crypto cert ${CERTNAMEBIGIP} from-local-file ${ENABLE}/${NAME}/${FILE}
# /usr/bin/tmsh install /sys crypto key ${CERTNAMEBIGIP} from-local-file ${ENABLE}/${NAME}/${KEY}
# /usr/bin/tmsh save /sys config
# /usr/bin/tmsh run /cm config-sync to-group ${DG}
# vi /etc/crontab (add on last line)
0 */6 * * * root /opt/agent/check.sh
0 22 * * * root /opt/agent/update.sh
Or add on root cron (contrab -e)
- After changed VARS in check.sh, run the first time to install client on server
- Go to the server and check the file was created: /opt/cert/client/{IP}.json
- Edit the file, change the "enable" to "true" and check the host name by reverse DNS, if not, change manually
- Back to client and run again the check.sh, note the folder with name of certificate are criated in /opt/agent/
- After changed VARS in update.sh, run script and the new folder "letsencypt" are created in /opt/agent/
- If you use the Apache or Nginx, edit the config file and set the path /opt/agent/letsencrypt to public key (fullchain.pem) and private key (privkey.pem)
- If you have multiples domains in your client server, you need to replicate scripts "check.sh" and "update.sh" to "check-domain1.sh", "check-domain2.sh", "update-domain1.sh", "update-domain2.sh" ... change "VARS" in scripts and you will need replicate the cron jobs