Skip to content

Instantly share code, notes, and snippets.

@jamesandariese
Created August 21, 2022 17:19
Show Gist options
  • Save jamesandariese/ebfca9ee9d0bcdc287b099a920e1621b to your computer and use it in GitHub Desktop.
Save jamesandariese/ebfca9ee9d0bcdc287b099a920e1621b to your computer and use it in GitHub Desktop.
self-enrolling your samba ad-dc in its kerberos
#!/bin/bash
HOST=$(hostname)
FQDN=$(hostname -f)
1>&2 echo "REMINDER: add additional SPNs by listing each as an additional argument."
if [ x = x"$FQDN" ] || [ "${FQDN%%.*}" != "$HOST" ] || [ "$HOST" = "$FQDN" ];then
(
exec 1>&2
echo "This system's FQDN and/or hostname are not configured properly"
echo "FQDN: $FQDN"
echo "hostname: $HOST"
)
exit 2
fi
1>&2 echo "echo self-enrolling machine in realm"
for h in "$HOST" "$FQDN";do
samba-tool domain exportkeytab --principal="$(echo "$h" | tr a-z A-Z)"'$' /etc/krb5.keytab
for spn in host restrictedkrbhost ldap cifs "$@";do
samba-tool domain exportkeytab --principal="$spn/$h" /etc/krb5.keytab
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment