TLS CERT CADDY #2673
-
I have read a lot of issue and post about that, but which is the best way to copy/share/use cert from caddy? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
I think this is the best summary I've seen of it #2626 (comment) |
Beta Was this translation helpful? Give feedback.
-
while we maybe work out a better method here is a little guide on how to copy and keep certificates up to date. Monitoring and Updating Postal Certificates1. Install inotify-toolsInstall the toolset which provides sudo apt-get update
sudo apt-get install inotify-tools 2. Create the Monitoring ScriptMake a script named nano /opt/postal/monitor_certs.sh Insert the following code: #!/bin/bash
CERT_DIR="/opt/postal/caddy-data/caddy/certificates/acme.zerossl.com-v2-dv90/YOURDOMAIN/"
CERT_FILE="${CERT_DIR}YOURDOMAIN.crt"
KEY_FILE="${CERT_DIR}YOURDOMAIN.key"
while true; do
inotifywait -e modify "$CERT_FILE" "$KEY_FILE"
# Copy the certificates to Postal's configuration directory
cp "$CERT_FILE" /opt/postal/config/smtp.crt
cp "$KEY_FILE" /opt/postal/config/smtp.key
# Adjust permissions to ensure Postal can read the certificates
chmod o+r /opt/postal/config/smtp.*
# Restart Postal to use the new certificates
postal stop && sleep 15 && postal start
done Make the script executable: chmod +x /opt/postal/monitor_certs.sh 3. Create a systemd ServiceMake a systemd service file: sudo nano /etc/systemd/system/monitor_certs.service Insert the following content: [Unit]
Description=Monitor Caddy Certificates for Postal
[Service]
ExecStart=/opt/postal/monitor_certs.sh
Restart=always
User=your_username
Group=your_groupname
[Install]
WantedBy=multi-user.target 4. Activate the ServiceReload the systemd daemons: sudo systemctl daemon-reload Enable and start the service: sudo systemctl enable monitor_certs.service
sudo systemctl start monitor_certs.service 5. Initial Manual Certificate CopyBefore the monitoring script takes over, you should manually copy the certificates for the first time: cp /opt/postal/caddy-data/caddy/certificates/acme.zerossl.com-v2-dv90/YOURDOMAIN/YOURDOMAIN.crt /opt/postal/config/smtp.crt
cp /opt/postal/caddy-data/caddy/certificates/acme.zerossl.com-v2-dv90/YOURDOMAIN/YOURDOMAIN.key /opt/postal/config/smtp.key
chmod o+r /opt/postal/config/smtp.* 6. Test the TLS ConnectionTo ensure everything is working correctly, test the TLS connection with openssl s_client -connect YOURDOMAIN:YOURPORT-starttls smtp |
Beta Was this translation helpful? Give feedback.
-
On this line:
there is a issue it should be:
with a break after :PORT since otherwise wont work. |
Beta Was this translation helpful? Give feedback.
-
Hi all.
With my purchased certificate, however, everything works correctly. |
Beta Was this translation helpful? Give feedback.
while we maybe work out a better method here is a little guide on how to copy and keep certificates up to date.
Monitoring and Updating Postal Certificates
1. Install inotify-tools
Install the toolset which provides
inotifywait
, used to monitor certificate changes.2. Create the Monitoring Script
Make a script named
monitor_certs.sh
:Insert the following code: