Lessons

Kerberos Authentication

Level: Advanced Module: Security & Authentication 8 min read Lesson 49 of 66

Overview

  • What you will learn: The Kerberos authentication protocol and its components (KDC, TGT, service tickets, realms), how to install and configure a Kerberos Key Distribution Center on Ubuntu, configure krb5.conf for clients, administer principals with kadmin, obtain and manage tickets with kinit, klist, and kdestroy, and kerberize network services such as SSH.
  • Prerequisites: Lesson 48 (AppArmor Mandatory Access Control), understanding of DNS and time synchronization
  • Estimated reading time: 30 minutes

Introduction

Kerberos is a network authentication protocol that uses symmetric-key cryptography and a trusted third party — the Key Distribution Center (KDC) — to authenticate users and services without transmitting passwords over the network. Instead of sending credentials directly to each service, a user obtains a time-limited ticket from the KDC and presents that ticket to prove identity.

Developed at MIT in the 1980s and now standardized as RFC 4120, Kerberos is the default authentication mechanism in Microsoft Active Directory and is widely used in Linux environments for single sign-on (SSO) across SSH, NFS, LDAP, and web services.

In this lesson you will learn the theory behind Kerberos authentication, then set up a fully functional KDC on Ubuntu Server, create user and service principals, and configure a client to obtain and use Kerberos tickets.

Kerberos Protocol Theory

Core Components

  • Key Distribution Center (KDC): The trusted server that issues tickets. It consists of two logical services: the Authentication Server (AS) and the Ticket Granting Server (TGS).
  • Realm: A Kerberos administrative domain, written in uppercase by convention (e.g., EXAMPLE.COM). All principals belong to a realm.
  • Principal: An identity known to Kerberos. User principals look like alice@EXAMPLE.COM; service principals look like HTTP/web.example.com@EXAMPLE.COM.
  • Ticket Granting Ticket (TGT): The initial ticket obtained from the AS. The TGT proves the user authenticated successfully and is used to request service tickets without re-entering the password.
  • Service Ticket: A ticket for a specific service, requested from the TGS by presenting the TGT.

Authentication Flow

The Kerberos exchange involves three steps:

  1. AS Exchange: The client sends the user principal name to the AS. The AS responds with a TGT encrypted with the user’s secret key (derived from the password). The client decrypts this using the password entered by the user.
  2. TGS Exchange: When the client needs to access a service, it presents the TGT to the TGS and requests a service ticket. The TGS returns a service ticket encrypted with the service’s secret key.
  3. AP Exchange: The client presents the service ticket to the application server. The server decrypts it with its own key and verifies the client’s identity.

At no point does the user’s password travel over the network. Tickets are time-limited (typically 10 hours) and include encrypted session keys for secure communication.

Installing the KDC on Ubuntu

Prerequisites

Kerberos is extremely sensitive to time differences. All machines in the realm must have clocks synchronized within 5 minutes. Ensure NTP is running on every host. DNS must also resolve hostnames correctly — both forward and reverse lookups.

# Verify time sync
$ timedatectl status
$ chronyc tracking

# Verify DNS
$ host kdc.example.com
$ host -t PTR 10.0.1.5

Install KDC Packages

# Install the KDC and admin server
$ sudo apt install krb5-kdc krb5-admin-server krb5-config

# During installation, you will be prompted for:
#   Default Kerberos realm: EXAMPLE.COM
#   Kerberos servers: kdc.example.com
#   Administrative server: kdc.example.com

Configure krb5.conf

# /etc/krb5.conf — KDC and client configuration
[libdefaults]
    default_realm = EXAMPLE.COM
    dns_lookup_realm = false
    dns_lookup_kdc = false
    ticket_lifetime = 10h
    renew_lifetime = 7d
    forwardable = true
    rdns = false

[realms]
    EXAMPLE.COM = {
        kdc = kdc.example.com
        admin_server = kdc.example.com
        default_domain = example.com
    }

[domain_realm]
    .example.com = EXAMPLE.COM
    example.com = EXAMPLE.COM

Create the Realm Database

# Initialize the KDC database (choose a strong master password)
$ sudo krb5_newrealm

# This creates the database in /var/lib/krb5kdc/
# and generates the stash file for the master key

Administering Principals with kadmin

Principals are managed using kadmin.local (on the KDC, no authentication needed) or kadmin (remote, requires an admin principal).

# Create an admin principal first
$ sudo kadmin.local
kadmin.local: addprinc admin/admin@EXAMPLE.COM
# Enter password for principal "admin/admin@EXAMPLE.COM":

# Configure ACL for the admin principal
# /etc/krb5kdc/kadm5.acl
*/admin@EXAMPLE.COM     *

# Restart the admin server
$ sudo systemctl restart krb5-admin-server

Managing User and Service Principals

# Connect with kadmin (remote or local)
$ sudo kadmin.local

# Add a user principal
kadmin.local: addprinc alice@EXAMPLE.COM

# Add a service principal for SSH on a host
kadmin.local: addprinc -randkey host/server1.example.com@EXAMPLE.COM

# Export the service keytab (for the application server)
kadmin.local: ktadd -k /tmp/server1.keytab host/server1.example.com@EXAMPLE.COM

# List all principals
kadmin.local: listprincs

# View principal details
kadmin.local: getprinc alice@EXAMPLE.COM

# Change a password
kadmin.local: cpw alice@EXAMPLE.COM

# Delete a principal
kadmin.local: delprinc bob@EXAMPLE.COM

Deploying Keytabs

# Copy the keytab to the target server securely
$ scp /tmp/server1.keytab admin@server1:/etc/krb5.keytab

# On the target server, verify the keytab
$ sudo klist -k /etc/krb5.keytab
Keytab name: FILE:/etc/krb5.keytab
KVNO Principal
---- ----------
   2 host/server1.example.com@EXAMPLE.COM

# Set correct permissions
$ sudo chmod 600 /etc/krb5.keytab
$ sudo chown root:root /etc/krb5.keytab

Client Operations: kinit, klist, kdestroy

# Install the client utilities
$ sudo apt install krb5-user

# Obtain a TGT (prompts for password)
$ kinit alice@EXAMPLE.COM
Password for alice@EXAMPLE.COM:

# List current tickets
$ klist
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: alice@EXAMPLE.COM

Valid starting       Expires              Service principal
01/15/2026 09:00:00  01/15/2026 19:00:00  krbtgt/EXAMPLE.COM@EXAMPLE.COM
    renew until 01/22/2026 09:00:00

# Renew a ticket before it expires
$ kinit -R

# Destroy all tickets (log out)
$ kdestroy

# Verify tickets are gone
$ klist
klist: No credentials cache found

Kerberizing SSH

Once Kerberos is configured, SSH can use GSSAPI authentication so users with valid TGTs can log in without passwords or SSH keys.

# On the SSH server — /etc/ssh/sshd_config
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
GSSAPIStrictAcceptorCheck yes

# Restart sshd
$ sudo systemctl restart sshd

# On the SSH client — /etc/ssh/ssh_config or ~/.ssh/config
Host *.example.com
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials yes

# Usage: obtain a TGT, then SSH without a password
$ kinit alice@EXAMPLE.COM
$ ssh server1.example.com
# No password prompt — Kerberos ticket is used

Key Takeaways

  • Kerberos provides network-wide single sign-on through ticket-based authentication — passwords never cross the network.
  • The Key Distribution Center (KDC) issues Ticket Granting Tickets (TGTs) and service tickets; all machines must have synchronized clocks and correct DNS.
  • Principals represent users (alice@REALM) and services (host/server@REALM); manage them with kadmin or kadmin.local.
  • Use kinit to obtain tickets, klist to view them, and kdestroy to remove them; keytabs allow services to authenticate without human interaction.
  • SSH, NFS, LDAP, and many other services support GSSAPI/Kerberos authentication for passwordless, ticket-based access.

What’s Next

In the next lesson you will learn about OpenLDAP Directory Service — how to build a centralized directory for user accounts, groups, and organizational data using the LDAP protocol.

繁體中文

概述

  • 學習目標:Kerberos 認證協定及其元件(KDC、TGT、服務票證、領域)、如何在 Ubuntu 上安裝和設定 Kerberos 金鑰分發中心、為客戶端設定 krb5.conf、使用 kadmin 管理主體、使用 kinit、klist 和 kdestroy 獲取和管理票證,以及為 SSH 等網路服務啟用 Kerberos 認證。
  • 先決條件:第 48 課(AppArmor 強制存取控制),了解 DNS 和時間同步
  • 預計閱讀時間:30 分鐘

簡介

Kerberos 是一種網路認證協定,使用對稱金鑰密碼學和受信任的第三方——金鑰分發中心(KDC)——來認證使用者和服務,而無需透過網路傳輸密碼。使用者從 KDC 獲取有時間限制的票證,然後出示該票證來證明身分,而不是直接將憑證發送給每個服務。

Kerberos 於 1980 年代在 MIT 開發,現已標準化為 RFC 4120,是 Microsoft Active Directory 中的預設認證機制,在 Linux 環境中廣泛用於 SSH、NFS、LDAP 和 Web 服務的單一登入(SSO)。

Kerberos 協定理論

核心元件

  • 金鑰分發中心(KDC):發行票證的受信任伺服器,包含認證伺服器(AS)和票證授權伺服器(TGS)。
  • 領域(Realm):Kerberos 管理域,按慣例大寫(如 EXAMPLE.COM)。
  • 主體(Principal):Kerberos 已知的身分。使用者主體如 alice@EXAMPLE.COM;服務主體如 HTTP/web.example.com@EXAMPLE.COM
  • 票證授權票證(TGT):從 AS 獲取的初始票證,用於請求服務票證而無需重新輸入密碼。
  • 服務票證:特定服務的票證,通過出示 TGT 從 TGS 請求。

認證流程

  1. AS 交換:客戶端向 AS 發送使用者主體名稱,AS 返回以使用者密鑰加密的 TGT。
  2. TGS 交換:客戶端向 TGS 出示 TGT 並請求服務票證。
  3. AP 交換:客戶端向應用程式伺服器出示服務票證。

在整個過程中,使用者的密碼永遠不會在網路上傳輸。

在 Ubuntu 上安裝 KDC

Kerberos 對時間差異非常敏感。領域中的所有機器必須在 5 分鐘內同步時鐘。確保每台主機都運行 NTP。

# 安裝 KDC 和管理伺服器
$ sudo apt install krb5-kdc krb5-admin-server krb5-config

# 初始化 KDC 資料庫
$ sudo krb5_newrealm

設定 krb5.conf

# /etc/krb5.conf
[libdefaults]
    default_realm = EXAMPLE.COM
    ticket_lifetime = 10h
    renew_lifetime = 7d
    forwardable = true

[realms]
    EXAMPLE.COM = {
        kdc = kdc.example.com
        admin_server = kdc.example.com
    }

使用 kadmin 管理主體

# 建立管理主體
$ sudo kadmin.local
kadmin.local: addprinc admin/admin@EXAMPLE.COM

# 建立使用者主體
kadmin.local: addprinc alice@EXAMPLE.COM

# 建立服務主體
kadmin.local: addprinc -randkey host/server1.example.com@EXAMPLE.COM

# 匯出 keytab
kadmin.local: ktadd -k /tmp/server1.keytab host/server1.example.com@EXAMPLE.COM

# 列出所有主體
kadmin.local: listprincs

客戶端操作:kinit、klist、kdestroy

# 獲取 TGT
$ kinit alice@EXAMPLE.COM

# 列出當前票證
$ klist

# 更新票證
$ kinit -R

# 銷毀所有票證
$ kdestroy

為 SSH 啟用 Kerberos

# SSH 伺服器 — /etc/ssh/sshd_config
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes

# SSH 客戶端 — ~/.ssh/config
Host *.example.com
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials yes

# 使用:獲取 TGT 後無密碼 SSH
$ kinit alice@EXAMPLE.COM
$ ssh server1.example.com

重點摘要

  • Kerberos 透過基於票證的認證提供全網路單一登入——密碼永遠不會在網路上傳輸。
  • KDC 發行 TGT 和服務票證;所有機器必須有同步的時鐘和正確的 DNS。
  • 主體代表使用者和服務;使用 kadminkadmin.local 管理它們。
  • 使用 kinit 獲取票證、klist 查看票證、kdestroy 移除票證;keytab 允許服務無需人工互動即可認證。
  • SSH、NFS、LDAP 等許多服務支援 GSSAPI/Kerberos 認證,實現無密碼的票證存取。

下一步

在下一課中,您將學習 OpenLDAP 目錄服務——如何使用 LDAP 協定建立集中式目錄來管理使用者帳戶、群組和組織資料。

日本語

概要

  • 学習内容:Kerberos 認証プロトコルとそのコンポーネント(KDC、TGT、サービスチケット、レルム)、Ubuntu での Kerberos 鍵配布センターのインストールと設定、クライアント用の krb5.conf 設定、kadmin によるプリンシパル管理、kinit・klist・kdestroy によるチケットの取得と管理、SSH などのネットワークサービスの Kerberos 化。
  • 前提条件:レッスン48(AppArmor 強制アクセス制御)、DNS と時刻同期の理解
  • 推定読了時間:30分

はじめに

Kerberos は、対称鍵暗号と信頼された第三者である鍵配布センター(KDC)を使用して、ネットワーク上でパスワードを送信せずにユーザーとサービスを認証するネットワーク認証プロトコルです。ユーザーは各サービスに直接資格情報を送信する代わりに、KDC から時間制限付きのチケットを取得し、そのチケットを提示して身元を証明します。

1980年代に MIT で開発され、現在は RFC 4120 として標準化されている Kerberos は、Microsoft Active Directory のデフォルト認証メカニズムであり、Linux 環境では SSH、NFS、LDAP、Web サービス全体のシングルサインオン(SSO)に広く使用されています。

Kerberos プロトコル理論

コアコンポーネント

  • 鍵配布センター(KDC):チケットを発行する信頼されたサーバー。認証サーバー(AS)とチケット認可サーバー(TGS)で構成。
  • レルム:Kerberos 管理ドメイン。慣例により大文字(例:EXAMPLE.COM)。
  • プリンシパル:Kerberos に既知のID。ユーザープリンシパルは alice@EXAMPLE.COM、サービスプリンシパルは HTTP/web.example.com@EXAMPLE.COM
  • チケット認可チケット(TGT):AS から取得する最初のチケット。パスワードの再入力なしにサービスチケットを要求するために使用。
  • サービスチケット:TGT を提示して TGS から要求する特定サービス用のチケット。

認証フロー

  1. AS 交換:クライアントが AS にユーザープリンシパル名を送信し、AS がユーザーの秘密鍵で暗号化された TGT を返す。
  2. TGS 交換:クライアントが TGS に TGT を提示してサービスチケットを要求。
  3. AP 交換:クライアントがアプリケーションサーバーにサービスチケットを提示。

プロセス全体を通じて、ユーザーのパスワードがネットワーク上を流れることはありません。

Ubuntu での KDC のインストール

Kerberos は時刻のずれに非常に敏感です。レルム内のすべてのマシンは5分以内にクロックを同期する必要があります。

# KDC と管理サーバーのインストール
$ sudo apt install krb5-kdc krb5-admin-server krb5-config

# KDC データベースの初期化
$ sudo krb5_newrealm

krb5.conf の設定

# /etc/krb5.conf
[libdefaults]
    default_realm = EXAMPLE.COM
    ticket_lifetime = 10h
    renew_lifetime = 7d
    forwardable = true

[realms]
    EXAMPLE.COM = {
        kdc = kdc.example.com
        admin_server = kdc.example.com
    }

kadmin によるプリンシパル管理

# 管理プリンシパルの作成
$ sudo kadmin.local
kadmin.local: addprinc admin/admin@EXAMPLE.COM

# ユーザープリンシパルの追加
kadmin.local: addprinc alice@EXAMPLE.COM

# サービスプリンシパルの追加
kadmin.local: addprinc -randkey host/server1.example.com@EXAMPLE.COM

# keytab のエクスポート
kadmin.local: ktadd -k /tmp/server1.keytab host/server1.example.com@EXAMPLE.COM

# すべてのプリンシパルの一覧
kadmin.local: listprincs

クライアント操作:kinit、klist、kdestroy

# TGT の取得
$ kinit alice@EXAMPLE.COM

# 現在のチケットの一覧
$ klist

# チケットの更新
$ kinit -R

# すべてのチケットの破棄
$ kdestroy

SSH の Kerberos 化

# SSH サーバー — /etc/ssh/sshd_config
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes

# SSH クライアント — ~/.ssh/config
Host *.example.com
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials yes

# 使用方法:TGT を取得してからパスワードなしで SSH
$ kinit alice@EXAMPLE.COM
$ ssh server1.example.com

重要ポイント

  • Kerberos はチケットベースの認証によりネットワーク全体のシングルサインオンを提供する。パスワードがネットワーク上を流れることはない。
  • KDC は TGT とサービスチケットを発行する。すべてのマシンはクロック同期と正しい DNS が必要。
  • プリンシパルはユーザーとサービスを表す。kadmin または kadmin.local で管理する。
  • kinit でチケットを取得、klist で表示、kdestroy で削除。keytab によりサービスは人の介入なしに認証可能。
  • SSH、NFS、LDAP など多くのサービスが GSSAPI/Kerberos 認証をサポートし、パスワードなしのチケットベースアクセスを実現する。

次のステップ

次のレッスンでは、OpenLDAP ディレクトリサービスについて学びます。LDAP プロトコルを使用して、ユーザーアカウント、グループ、組織データの集中ディレクトリを構築する方法を学びます。

You Missed