Featured image of post Kerberos in a Nutshell

Kerberos in a Nutshell

Understanding this secure, ticket-based authentication system

Introduction

Ever wondered how your Windows domain login works? Or how secure authentication happens in massive networks?
The answer is Kerberos—a secure, ticket-based authentication protocol that powers many modern authentication systems, including Active Directory.


The History of Kerberos

Kerberos was developed in the 1980s at MIT as part of Project Athena, an initiative to create a secure, networked computing environment.

Why Was Kerberos Created?

  • Early authentication methods were insecure—plain-text passwords were transmitted over the network.
  • Systems needed a way to authenticate users securely across distributed networks.
  • It had to be resistant to eavesdropping and replay attacks.

Kerberos is named after the three-headed dog from Greek mythology that guards the gates of the underworld—just like how Kerberos authentication guards access to network resources.

Key Innovations of Kerberos

Single Sign-On (SSO) → Authenticate once, use multiple services.
Ticket-Based Authentication → No passwords sent after initial login.
Mutual Authentication → Both client and server verify each other.
Time-Based Authentication → Prevents replay attacks.

Further Reading:


How Kerberos Works

Kerberos follows a three-step process involving three main components:

  1. Key Distribution Center (KDC) → Issues authentication tickets.
  2. Ticket Granting Service (TGS) → Issues service-specific tickets.
  3. Service Principal (SP) → The actual service being accessed.

Step-by-Step Kerberos Authentication

  1. User logs in → Sends username to the Authentication Server (AS).
  2. AS verifies identity → Returns a Ticket Granting Ticket (TGT).
  3. User requests access to a service → Sends TGT to the Ticket Granting Service (TGS).
  4. TGS verifies and grants service ticket → User can now access the service without re-entering credentials.

This ensures that passwords never travel over the network, reducing attack risks.


Kerberos vs. Other Authentication Methods

FeatureKerberosNTLM (Windows)OAuth 2.0
Single Sign-On✅ Yes❌ No✅ Yes
Mutual Authentication✅ Yes❌ No✅ Yes
Ticket-Based✅ Yes❌ No (Challenge/Response)✅ Yes (Tokens)
Used ByWindows, Linux, macOSWindows-onlyWeb & API Authentication

💡 Verdict: Kerberos is ideal for enterprise authentication, while OAuth dominates web-based logins.


10 Kerberos Code Examples

1. Checking Kerberos Tickets in Windows (Command Line)

1
klist

2. Authenticating with Kerberos in Linux

1
kinit user@DOMAIN.COM

3. Viewing Active Kerberos Sessions

1
klist -e

4. Writing a Basic Kerberos Client in Python

1
2
3
4
5
6
import kerberos

_, krb_context = kerberos.authGSSClientInit("HTTP@server.domain.com")
kerberos.authGSSClientStep(krb_context, "")
token = kerberos.authGSSClientResponse(krb_context)
print("Kerberos Token:", token)

5. Connecting to Kerberos-Protected LDAP Server (Python)

1
2
3
4
5
import ldap

server = "ldap://server.domain.com"
conn = ldap.initialize(server)
conn.sasl_interactive_bind_s("", ldap.sasl.gssapi())

6. Using Kerberos in C (MIT Kerberos API)

1
2
3
4
5
#include <krb5.h>

krb5_context ctx;
krb5_init_context(&ctx);
printf("Kerberos context initialized!\n");

7. Configuring Kerberos in Linux (/etc/krb5.conf)

1
2
[libdefaults]
default_realm = DOMAIN.COM

8. Testing Kerberos Authentication in Java

1
2
3
4
5
6
7
import javax.security.auth.Subject;
import javax.security.auth.kerberos.KerberosTicket;
import java.util.Set;

Subject subject = new Subject();
Set<KerberosTicket> tickets = subject.getPrivateCredentials(KerberosTicket.class);
System.out.println("Kerberos Tickets: " + tickets);

9. Configuring Kerberos in Windows (krb5.ini)

1
2
[libdefaults]
default_realm = DOMAIN.COM

10. Creating a Kerberos Keytab File

1
2
3
ktutil
add_entry -password -p user@DOMAIN.COM -k 1 -e aes256-cts
write_kt user.keytab

Key Takeaways

  • Kerberos is a secure authentication protocol used in Active Directory and Linux systems.
  • It prevents password transmission by using ticket-based authentication.
  • It competes with NTLM (Windows) and OAuth (Web) for authentication use cases.

References

  1. Kerberos Wikipedia
  2. MIT Kerberos Project
  3. Kerberos for Windows
  4. OAuth vs. Kerberos