How to rebuild Kerberos on Mac OS X 10.6, 10.7 & 10.8

After a lot of searching and trying I have finally come up with a way of rebuild the local KDC in OS X.

This script covers 10.6 up to 10.8.

rebuildKerberos.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash

## rebuildKerberos
## by Daniel Shane 06/12/2012
## to use : sudo rebuildKerberos /Volumes/Macintosh\ HD

## Check for Root
if [ "$(id -u)" != "0" ]
then
   echo "rebuildKerberos must be run as root"
   exit 1
fi

## Check for Path
if [ -z "$1" ]
then
    echo "rebuildKerberos needs a path to the volume to work on e.g. /Volumes/Macintosh\ HD"
    exit 1
fi

## Rebuild System Keychain
/usr/sbin/systemkeychain -k "$1"/Library/Keychains/System.keychain -C -f

## Remove Old KDC Files
rm -rf "$1"/private/var/db/krb5kdc
rm -rf "$1"/private/etc/krb5.keytab


## Enable the configureLocalKDC LaunchD Item
/usr/bin/defaults delete "$1"/System/Library/LaunchDaemons/com.apple.configureLocalKDC Disabled &>/dev/null

## Set Ownership on the configureLocalKDC LaunchD Item
chown root:wheel "$1"/System/Library/LaunchDaemons/com.apple.configureLocalKDC.plist

## Kill .configureLocalKDC from /var/db
rm -f "$1"/private/var/db/.configureLocalKDC
echo "$1" is now ready to be booted from