Source

mindref-sbin / kdc-addhost

Full commit
#!/bin/bash

type=host
if [ ! -z $1 ]; then type=$1; fi

read -s -p "Password for admin: " passwd; echo
host=`hostname -f`

if [ -z `kadmin -p admin -w $passwd -q "listprincs" | grep $type/$host` ]; then
    kadmin -p admin -w $passwd -q "addprinc -randkey $type/$host"
fi

if [ ! -f /etc/krb5.keytab -o -z "`klist -ke | grep $type/$host`" ]; then
    kadmin -p admin -w $passwd -q "ktadd $type/$host"
fi