Skip to content

Instantly share code, notes, and snippets.

@techdad
Created March 30, 2017 16:44
Show Gist options
  • Save techdad/e54927b20e5ea0d7054c1df5ad2d145c to your computer and use it in GitHub Desktop.
Save techdad/e54927b20e5ea0d7054c1df5ad2d145c to your computer and use it in GitHub Desktop.
TSIG (or nsupdate) key generation, take two (improved)
#!/usr/bin/env bash
# quick and dirty TSIG generation script
# version 2
# mostly taken directly from https://github.com/Neilpang/acme.sh/tree/master/dnsapi
# (with a sprinkle of added command-line switching)
# define key params
size="512"
algo="hmac-sha$size"
# get key name
if [[ -z $1 ]]; then
echo "Error: Usage: $0 <key-name>"
exit 1
else
keyname="$1"
fi
tsig=$(dnssec-keygen -a $algo -b $size -n USER -K /tmp $keyname)
cat <<EOF
key "$keyname" {
algorithm $algo;
secret "$(awk '/^Key/{print $2}' /tmp/$tsig.private)";
};
EOF
rm -f /tmp/$tsig.{private,key}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment