Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F1458945
DKIM key generator for Postfix
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
valerio.bozzolan
Jan 6 2021, 15:17
2021-01-06 15:17:05 (UTC+1)
Size
1 KB
Referenced Files
None
Subscribers
None
DKIM key generator for Postfix
View Options
#!/bin/bash
#
# Generate a DKIM key for Postfix
#
# Project info
# https://gitpull.it/w/kiss_libre_hosting_panel/
#
# Updates
# https://gitpull.it/P13
#
# This script is in public domain.
# 2020 - Valerio Bozzolan
###################################################
# die in case of errors
set -e
# expected pathnames
POSTFIX=/etc/postfix
DKIM="$POSTFIX"/dkim
KEYTABLE="$DKIM"/keytable
SIGNINGTABLE="$DKIM"/signingtable
DKIM_KEYS="$DKIM"/dkimkeys
# no domain no party
domain="$1"
if [ -z "$domain" ]; then
echo "Please insert the domain name and press enter"
read domain
fi
# no selector no party
selector="$2"
if [ -z "$2" ]; then
date="`date +%Y%m`"
# make domain shorter
domainshort="${domain:0:10}"
# strip dots
domainshort=$(echo "$domainshort" | sed 's/\.//g')
selector="$domainshort""$date"
fi
# expected pathnames
keytablename="$selector"key
expected_filename_prv="$selector".private
expected_filename_txt="$selector".txt
expected_filepath_prv="$DKIM_KEYS"/"$expected_filename_prv"
expected_filepath_txt="$DKIM_KEYS"/"$expected_filename_txt"
# key generation
opendkim-genkey --verbose --bits=1024 "--domain=$domain" "--selector=$selector" "--directory=$DKIM_KEYS"
# this line should be at the beginning of the file
sed -i "1s/^/*@$domain $keytablename\n/" "$SIGNINGTABLE"
# this line can be appended at the end of the table
echo "$keytablename $domain:$selector:$expected_filepath_prv" >> "$KEYTABLE"
# eventually fix privileges
chown --verbose opendkim: "$expected_filepath_prv" "$expected_filepath_txt"
cat "$expected_filepath_txt"
echo
echo "Done!"
echo " systemctl reload opendkim"
echo " opendkim-testkey -d '$domain' -s '$selector' -vvv"
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
46852
Default Alt Text
DKIM key generator for Postfix (1 KB)
Attached To
Mode
P13 DKIM key generator for Postfix
Attached
Detach File
Event Timeline
Log In to Comment