Your submission was sent successfully! Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

You have successfully unsubscribed! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates about Ubuntu and upcoming events where you can meet our team.Close

How to install a Kerberos server

Note:
This documentation has moved to a new home! Please update your bookmarks to the new URL for the up-to-date version of this page.

For this discussion, we will create an MIT Kerberos domain with the following features (edit them to fit your needs):

  • Realm: EXAMPLE.COM
  • Primary KDC: kdc01.example.com
  • Secondary KDC: kdc02.example.com
  • User principal: ubuntu
  • Admin principal: ubuntu/admin

Prerequisites

Before installing the Kerberos server, a properly configured DNS server is needed for your domain. Since the Kerberos realm (by convention) matches the domain name, this section uses the EXAMPLE.COM domain configured in the primary server section of the DNS documentation.

Also, Kerberos is a time sensitive protocol. If the local system time between a client machine and the server differs by more than five minutes (by default), the workstation will not be able to authenticate. To correct the problem all hosts should have their time synchronized using the same Network Time Protocol (NTP) server. Check out the NTP chapter for more details.

Install the Kerberos packages

The first step in creating a Kerberos realm is to install the krb5-kdc and krb5-admin-server packages. From a terminal enter:

sudo apt install krb5-kdc krb5-admin-server

You will be asked at the end of the install to supply the hostname for the Kerberos and Admin servers for the realm, which may or may not be the same server. Since we are going to create the realm, and thus these servers, type in the full hostname of this server.

Note:
By default the realm name will be domain name of the Key Distribution Center (KDC) server.

Next, create the new realm with the kdb5_newrealm utility:

sudo krb5_newrealm

It will ask you for a database master password, which is used to encrypt the local database. Chose a secure password: its strength is not verified for you.

Configure the Kerberos server

The questions asked during installation are used to configure the /etc/krb5.conf and /etc/krb5kdc/kdc.conf files. The former is used by the Kerberos 5 libraries, and the latter configures the KDC. If you need to adjust the KDC settings, edit the file and restart the krb5-kdc daemon. If you need to reconfigure Kerberos from scratch, perhaps to change the realm name, you can do so by typing:

sudo dpkg-reconfigure krb5-kdc

Note:
The manpage for krb5.conf is in the krb5-doc package.

Let’s create our first principal. Since there is no principal create yet, we need to use kadmin.local, which uses a local UNIX socket to talk to the KDC, and requires root privileges:

$ sudo kadmin.local
Authenticating as principal root/[email protected] with password.
kadmin.local: addprinc ubuntu
WARNING: no policy specified for [email protected]; defaulting to no policy
Enter password for principal "[email protected]": 
Re-enter password for principal "[email protected]": 
Principal "[email protected]" created.
kadmin.local: quit

To be able to use kadmin remotely, we should create an admin principal. Convention suggests it should be an admin instance, as that also makes creating a generic Access Control List (ACL) easier. Let’s create an admin instance for the ubuntu principal:

$ sudo kadmin.local
Authenticating as principal root/[email protected] with password.
kadmin.local: addprinc ubuntu/admin
WARNING: no policy specified for ubuntu/[email protected]; defaulting to no policy
Enter password for principal "ubuntu/[email protected]": 
Re-enter password for principal "ubuntu/[email protected]": 
Principal "ubuntu/[email protected]" created.
kadmin.local: quit

Next, the new admin principal needs to have the appropriate ACL permissions. The permissions are configured in the /etc/krb5kdc/kadm5.acl file:

ubuntu/[email protected]        *

You can also use a more generic form for this ACL:

*/[email protected]        *

The above will grant all privileges to any admin instance of a principal. See the kadm5.acl manpage for details.

Now restart the krb5-admin-server for the new ACL to take effect:

sudo systemctl restart krb5-admin-server.service

The new user principal can be tested using the kinit utility:

$ kinit ubuntu/admin
Password for ubuntu/[email protected]:

After entering the password, use the klist utility to view information about the Ticket Granting Ticket (TGT):

$ klist
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: ubuntu/[email protected]

Valid starting     Expires            Service principal
04/03/20 19:16:57  04/04/20 05:16:57  krbtgt/[email protected]
     renew until 04/04/20 19:16:55

Where the cache filename krb5cc_1000 is composed of the prefix krb5cc_ and the user id (UID), which in this case is 1000.

kinit will inspect /etc/krb5.conf to find out which KDC to contact, and the corresponding address. The KDC can also be found via DNS lookups for special TXT and SRV records. You can add these records to your example.com DNS zone:

_kerberos._udp.EXAMPLE.COM.     IN SRV 1  0 88  kdc01.example.com.
_kerberos._tcp.EXAMPLE.COM.     IN SRV 1  0 88  kdc01.example.com.
_kerberos._udp.EXAMPLE.COM.     IN SRV 10 0 88  kdc02.example.com. 
_kerberos._tcp.EXAMPLE.COM.     IN SRV 10 0 88  kdc02.example.com. 
_kerberos-adm._tcp.EXAMPLE.COM. IN SRV 1  0 749 kdc01.example.com.
_kpasswd._udp.EXAMPLE.COM.      IN SRV 1  0 464 kdc01.example.com.

See the DNS chapter for detailed instructions on setting up DNS.

A very quick and useful way to troubleshoot what kinit is doing is to set the environment variable KRB5_TRACE to a file, or stderr, and it will show extra information. The output is quite verbose:

$ KRB5_TRACE=/dev/stderr kinit ubuntu/admin
[2898] 1585941845.278578: Getting initial credentials for ubuntu/[email protected]
[2898] 1585941845.278580: Sending unauthenticated request
[2898] 1585941845.278581: Sending request (189 bytes) to EXAMPLE.COM
[2898] 1585941845.278582: Resolving hostname kdc01.example.com
(...)

Your new Kerberos realm is now ready to authenticate clients.

This page was last modified 2 months ago. Help improve this document in the forum.