Rotate NFS Keytabs Safely on AlmaLinux 10 (kvno, ktadd, Overlapping Keys)

Kerberos series. Previous: Secure NFS with MIT Kerberos on AlmaLinux 10. Earlier: Set Up an MIT Kerberos KDC, Create and Manage Kerberos Keytabs, Primary and Replica KDC, Configure a Kerberos Client. This post covers changing the keys behind a Kerberized NFS share without breaking clients.

Every Kerberized NFS setup depends on long-lived keys in keytab files: the nfs/ key on the server and a host/ (or nfs/) key on every client. Changing them is easy. Changing them without breaking clients takes some planning, because tickets already issued with the old key stay in use for up to a day. This guide covers how key version numbers (kvno) work, how ktadd adds a new key alongside the old one in the keytab, how long to keep the old key, how ktremove ... old and k5srvutil delold clean up, what cpw -randkey -keepold and ktadd -norandkey actually do, and the exact errors you see when the order goes wrong. The commands are the same on AlmaLinux 10, RHEL 10 and 9, Rocky Linux, Oracle Linux and CentOS Stream, because they all ship MIT Kerberos (krb5 1.21) and the same nfs-utils.

Every command output in this post comes from a lab run with the AlmaLinux 10 packages (krb5-server 1.21.3, gssproxy 0.9.2, nfs-utils 2.8.3). The section What was tested and what was not lists what the lab could not do, such as a real kernel NFS mount.

Lab layout used in this guide

HostRolePrincipals in its keytab
kdc1.example.comMIT KDC for realm EXAMPLE.COM(none needed)
nfs1.example.comNFS server, gssproxynfs/nfs1.example.com, host/nfs1.example.com
client1.example.comNFS client, rpc.gssdhost/client1.example.com

This is the same layout as the Secure NFS post. In the outputs below the lab keytab paths were shortened to /etc/krb5.keytab.

How key versions work

Each time a principal’s key changes, the KDC increases its key version number (kvno). A service ticket records which kvno it was encrypted with, and the service looks up exactly that kvno in its keytab. Three facts follow, and the lab confirmed each:

  • The KDC keeps only the new key after a normal ktadd or cpw -randkey. getprinc lists only the new kvno.
  • The keytab can hold several kvnos of the same principal. ktadd adds the new kvno and keeps the old entries in the file.
  • Tickets that clients already hold still use the old kvno until they expire (24 hours with the defaults in this series). The server accepts them as long as it still has the old key in its keytab. Removing it too early is what breaks clients.

The same applies to the client’s host/ key, but in the other direction: the client uses that key to get its machine ticket (rpc.gssd does the equivalent of kinit -k), and the KDC only accepts the current key for that. An old key in the client keytab does not help it log in, so the client keytab must have the new key from the moment the KDC does.

Prerequisites

  • A working Kerberized NFS setup as in Secure NFS with MIT Kerberos, and the keytab basics.
  • Admin access to the KDC: kadmin.local as root on the KDC, or a */admin principal for remote kadmin.
  • Root on the NFS server and clients (the keytab is /etc/krb5.keytab, mode 0600, owner root).
  • Working time sync (chrony) on all hosts.
  • The krb5-workstation package on servers and clients for klist, kvno, kadmin, ktutil and k5srvutil.
dnf install -y krb5-workstation

Step 1: Record the current state

Before you change anything, write down the kvno in the KDC, in each keytab and in a fresh ticket, and back up the keytab. On the NFS server:

cp -p /etc/krb5.keytab /root/krb5.keytab.$(date +%F)
klist -ke /etc/krb5.keytab
kadmin -p admin/admin -q "getprinc nfs/nfs1.example.com"

Lab output after the first ktadd (kvno 2: addprinc -randkey creates kvno 1 and ktadd immediately randomizes it again):

Keytab name: FILE:/etc/krb5.keytab
KVNO Principal
---- --------------------------------------------------------------------------
   2 nfs/nfs1.example.com@EXAMPLE.COM (aes256-cts-hmac-sha384-192)
   2 nfs/nfs1.example.com@EXAMPLE.COM (aes128-cts-hmac-sha256-128)
   2 nfs/nfs1.example.com@EXAMPLE.COM (aes256-cts-hmac-sha1-96)
   2 nfs/nfs1.example.com@EXAMPLE.COM (aes128-cts-hmac-sha1-96)
   2 host/nfs1.example.com@EXAMPLE.COM (aes256-cts-hmac-sha384-192)
   ...

Check that a ticket from the KDC matches the keytab. kvno -k fetches a service ticket and decrypts it with the keytab, which is the best quick test that the two agree. Run it as any user with a ticket, on a host that can read the keytab:

kvno nfs/nfs1.example.com
nfs/nfs1.example.com@EXAMPLE.COM: kvno = 2

kvno -k /etc/krb5.keytab nfs/nfs1.example.com
nfs/nfs1.example.com@EXAMPLE.COM: kvno = 2, keytab entry valid

Also note the maximum ticket life. That is the minimum time you must keep the old key:

kadmin -p admin/admin -q "getprinc nfs/nfs1.example.com" | grep -E "Maximum|Key: vno"
Maximum ticket life: 1 day 00:00:00
Maximum renewable life: 7 days 00:00:00
Key: vno 2, aes256-cts-hmac-sha384-192
...

Step 2: Rotate the NFS server keys (nfs/ and host/)

Run ktadd on the NFS server, writing to the keytab the server really uses. That changes the key in the KDC and writes the new key into the keytab in one step, so there is no time when the KDC hands out tickets the server cannot read. You can list both principals in one command:

kadmin -p admin/admin -q "ktadd -k /etc/krb5.keytab nfs/nfs1.example.com host/nfs1.example.com"

On the KDC itself, kadmin.local takes the same command. The lab used it like this:

kadmin.local -q "ktadd -k /etc/krb5.keytab nfs/nfs1.example.com host/nfs1.example.com"
klist -ke /etc/krb5.keytab
   2 nfs/nfs1.example.com@EXAMPLE.COM (aes256-cts-hmac-sha384-192)
   ...
   2 host/nfs1.example.com@EXAMPLE.COM (aes128-cts-hmac-sha1-96)
   3 nfs/nfs1.example.com@EXAMPLE.COM (aes256-cts-hmac-sha384-192)
   3 nfs/nfs1.example.com@EXAMPLE.COM (aes128-cts-hmac-sha256-128)
   3 nfs/nfs1.example.com@EXAMPLE.COM (aes256-cts-hmac-sha1-96)
   3 nfs/nfs1.example.com@EXAMPLE.COM (aes128-cts-hmac-sha1-96)
   3 host/nfs1.example.com@EXAMPLE.COM (aes256-cts-hmac-sha384-192)
   ...

The keytab now holds both kvno 2 and kvno 3. The KDC holds only kvno 3:

kadmin.local -q "getprinc nfs/nfs1.example.com"
Number of keys: 4
Key: vno 3, aes256-cts-hmac-sha384-192
Key: vno 3, aes128-cts-hmac-sha256-128
Key: vno 3, aes256-cts-hmac-sha1-96
Key: vno 3, aes128-cts-hmac-sha1-96

Warning: running kadmin.local ktadd on the KDC without copying the file to the server, or into the wrong file, still changes the key in the KDC. The server’s real keytab is then out of date, and every new ticket fails (see Step 5). If you must create the keytab on the KDC, copy it to the server right away over a secure channel (for example scp as root, then chmod 600 and restorecon /etc/krb5.keytab), and merge it rather than overwrite it, so the old kvno stays (see the ktutil example below).

Verify the overlap

With both kvnos in the keytab, both old and new tickets work. In the lab, a user kept the kvno 2 ticket in its cache from before the rotation, and the server (a GSS-API accept test against the keytab) still accepted it. kvno -k confirms it:

klist
11/26/26 03:15:48  11/27/26 03:15:48  nfs/nfs1.example.com@EXAMPLE.COM
kvno -k /etc/krb5.keytab nfs/nfs1.example.com
nfs/nfs1.example.com@EXAMPLE.COM: kvno = 2, keytab entry valid

A fresh ticket (after kdestroy and kinit) gets the new key, and it was accepted too:

kvno nfs/nfs1.example.com
nfs/nfs1.example.com@EXAMPLE.COM: kvno = 3

gssproxy did not need a restart. The lab ran gssproxy with the keytab in its cred_store, rotated the key twice and removed the old kvno; each time gssproxy used the changed file straight away. This matches what the Secure NFS post found. systemctl reload gssproxy after a key change does no harm if you prefer to be sure (the reload was not tested here).

Step 3: Rotate the client host keys

For a client, the order is the same: run ktadd on the client so the KDC and the keytab change together. Two methods work:

Option A: kadmin with an admin principal

kadmin -p admin/admin -q "ktadd -k /etc/krb5.keytab host/client1.example.com"

Option B: k5srvutil (no admin password needed)

k5srvutil logs in to kadmin with the keytab’s own key and changes that key, so a host can rotate its own key without an admin password. It needs kadmind on the KDC to be reachable (admin_server in krb5.conf, TCP port 749 by default). The lab tested it against a kadmind on another port:

k5srvutil -f /etc/krb5.keytab list
k5srvutil -f /etc/krb5.keytab change
Authenticating as principal host/client1.example.com@EXAMPLE.COM with keytab /etc/krb5.keytab.
Entry for principal host/client1.example.com@EXAMPLE.COM with kvno 5, encryption type aes256-cts-hmac-sha384-192 added to keytab WRFILE:/etc/krb5.keytab.
...

change adds the new kvno and keeps the old ones; delold later removes everything but the newest (Step 4). The man page says change fails if the keytab’s kvno does not match the KDC. In the lab, a keytab that was already out of date failed earlier, at login:

k5srvutil -f /etc/krb5.keytab.stale change
kadmin: Preauthentication failed while initializing kadmin interface

What changes for an existing client

  • Machine tickets already issued stay valid. In the lab, a host/client1 ticket-granting ticket obtained before the rotation was still used to get an nfs/ service ticket afterwards. That ticket is encrypted with the KDC’s krbtgt key, not the host key, so nothing on an active mount should notice. This was not tested with a real rpc.gssd.
  • The next login needs the new key. rpc.gssd gets a new machine ticket from /etc/krb5.keytab when the old one expires (it stores machine tickets in /tmp by default, see -d in rpc.gssd(8)). It looks for <HOST>$, root/, nfs/ and host/ principals in that order (rpc.gssd(8)), so rotate whichever of these the client keytab actually has, and rotate both if it has nfs/ and host/.
  • Restarting rpc.gssd is not required by Kerberos, because it reads the keytab when it needs a new machine ticket. If you replaced the keytab while it was stale, systemctl restart rpc-gssd and removing the old /tmp/krb5ccmachine_EXAMPLE.COM makes it fetch a new ticket immediately. Neither command was tested in this lab.

Step 4: Wait, then remove the old kvno

Keep the old key at least as long as the longest ticket that may have been issued with it: the Maximum ticket life of the service principal and of the realm (max_life in kdc.conf), plus a few minutes for clock skew. With the series defaults that is 24 hours. The kernel also keeps an NFS security context for the lifetime of the ticket it was made from (rpc.gssd -t in the man page), so waiting the full ticket lifetime matters. Waiting longer does not hurt; many admins clean up a week later.

Then remove the old entries on each host. ktremove ... old keeps only the highest kvno for that principal; a number removes exactly that kvno; all removes the principal completely:

kadmin.local -q "ktremove -k /etc/krb5.keytab nfs/nfs1.example.com old"
Entry for principal nfs/nfs1.example.com with kvno 2 removed from keytab WRFILE:/etc/krb5.keytab.
Entry for principal nfs/nfs1.example.com with kvno 2 removed from keytab WRFILE:/etc/krb5.keytab.
Entry for principal nfs/nfs1.example.com with kvno 2 removed from keytab WRFILE:/etc/krb5.keytab.
Entry for principal nfs/nfs1.example.com with kvno 2 removed from keytab WRFILE:/etc/krb5.keytab.

kadmin.local -q "ktremove -k /etc/krb5.keytab host/nfs1.example.com 2"

ktremove only edits the local keytab file and does not change anything in the KDC. The kadmin man page notes it needs no kadmin privileges, so on the NFS server you can run it through remote kadmin with any principal you can log in as. On a client, k5srvutil delold does the same for every principal in the keytab:

k5srvutil -f /etc/krb5.keytab delold
Entry for principal host/client1.example.com@EXAMPLE.COM with kvno 5 removed from keytab WRFILE:/etc/krb5.keytab.
...

Check the result with klist -ke and kvno -k again. A client that still had an old ticket gets the error shown in the troubleshooting table until it gets a new ticket. In the lab that happened exactly when expected:

accept_sec_context: Request ticket server nfs/nfs1.example.com@EXAMPLE.COM kvno 2 not found in keytab; ticket is likely out of date

ktutil is the interactive alternative when you need to look at or merge keytabs (the lab tested rkt, list and delent):

ktutil
ktutil:  rkt /etc/krb5.keytab
ktutil:  rkt /root/new-from-kdc.keytab
ktutil:  list
ktutil:  delent 1
ktutil:  wkt /etc/krb5.keytab.new
ktutil:  q

cpw -randkey -keepold and ktadd -norandkey

These two options come up in many rotation guides. The lab shows what they really do.

cpw -randkey -keepold

cpw -randkey -keepold sets a new random key in the KDC and keeps the old key in the KDC database. It does not write a keytab:

kadmin.local -q "cpw -randkey -keepold host/client1.example.com"
Key for "host/client1.example.com@EXAMPLE.COM" randomized.

kadmin.local -q "getprinc host/client1.example.com"
Number of keys: 8
Key: vno 3, aes256-cts-hmac-sha384-192
...
Key: vno 2, aes256-cts-hmac-sha384-192
...

Keeping the old key in the KDC does not let a host with the old keytab log in. With kvno 2 and 3 in the database and only kvno 2 in the client keytab, kinit -k failed:

kinit -k -t /etc/krb5.keytab host/client1.example.com
kinit: Preauthentication failed while getting initial credentials

The kadmin man page says -keepold “is usually not necessary except perhaps for krbtgt principals”. For NFS service and host keys, the overlap belongs in the keytab, which plain ktadd already gives you.

ktadd -norandkey

ktadd -norandkey copies the keys that are already in the KDC into a keytab without changing them. It only works with kadmin.local or with the extract-keys (e) privilege, which the * ACL entry does not include. With a remote admin the lab got:

kadmin: Operation requires ``extract-keys'' privilege while changing nfs/nfs1.example.com's key

It is the tool for repairing a keytab without changing the key again (for example after you rotated on the KDC and lost the file). Two things to know:

  • It exports every kvno the KDC still holds, so after a -keepold change you get both. It does not skip entries already in the file, so the lab keytab ended up with each kvno 2 entry twice. That does not break anything (kinit -k still worked), but writing to an empty file and merging with ktutil keeps it clean.
  • It cannot be combined with -e: cannot specify keysaltlist when not changing key.

Old keys kept with -keepold stay in the KDC until you purge them:

kadmin.local -q "purgekeys -keepkvno 3 host/client1.example.com"
Old keys for principal "host/client1.example.com@EXAMPLE.COM" purged.

Step 5: Verify

  1. On every host: klist -ke /etc/krb5.keytab shows the new kvno for each principal (and the old one until Step 4).
  2. From a client with a user ticket: kvno nfs/nfs1.example.com shows the new kvno; on the server kvno -k /etc/krb5.keytab nfs/nfs1.example.com says keytab entry valid.
  3. On each client as root: kinit -k host/client1.example.com && klist && kdestroy proves the machine key works.
  4. On a client, read a file on the Kerberos mount as a user after kdestroy; kinit, then klist shows a new nfs/ ticket. (Not tested in this lab, which had no kernel NFS.)

Troubleshooting

All messages below were reproduced in the lab.

MessageCauseFix
Request ticket server nfs/nfs1.example.com@EXAMPLE.COM kvno 3 not found in keytab; keytab is likely out of dateThe KDC has a newer key than the server keytab (rotated on the KDC or into another file, keytab not copied)Run ktadd -norandkey on the KDC to a new file and merge it into the server keytab, or ktadd on the server again
... kvno 2 not found in keytab; ticket is likely out of dateThe old kvno was removed while clients still had tickets for itPut the backed-up entries back (rollback), or users run kinit again / wait for the ticket to expire
kvno = 3, keytab entry invalid followed by Wrong principal in request while decrypting ticketkvno -k run against a keytab that lacks the current kvnoSame as the first row
kinit: Preauthentication failed while getting initial credentials with kinit -kThe host keytab lacks the KDC’s current key (also with -keepold)Run ktadd -norandkey on the KDC, copy the key to the client; check with klist -ke against getprinc
kadmin: Preauthentication failed while initializing kadmin interface from k5srvutilThe keytab is already out of date, so it cannot log in to kadminRepair it with an admin (ktadd -norandkey or ktadd)
Operation requires ``extract-keys'' privilegektadd -norandkey through remote kadminUse kadmin.local on the KDC or grant e in kadm5.acl to a dedicated admin principal
Key version number for principal in key table is incorrect while retrieving highest kvno from keytabktremove with a kvno that is not in the file (the wording is misleading)klist -ke and use a kvno that exists
cannot specify keysaltlist when not changing keyktadd -norandkey -e ...Drop -e, or rotate with ktadd -e

Rollback and recovery

Because the KDC already holds only the new key after ktadd, you cannot go back to the old key. Recovery always means bringing the keytabs up to the KDC’s current kvno:

  1. Clients rejected right after cleanup: restore the backup from Step 1 next to the current entries, so both kvnos are back. Merge with ktutil (rkt backup, rkt current, wkt to a new file), check with klist -ke, then move the new file into place with mode 0600 and restorecon.
  2. Server keytab missing the new kvno: on the KDC run kadmin.local -q "ktadd -norandkey -k /root/nfs1-fix.keytab nfs/nfs1.example.com host/nfs1.example.com", copy it securely to the server and merge it. The key does not change again, so tickets already issued with the new kvno start working.
  3. Client cannot get a machine ticket: the same with host/client1.example.com, then kinit -k to check, and restart rpc-gssd if it gave up (untested).
  4. Lost or leaked keytab: do not restore it; run ktadd again (new kvno) and, if it leaked, remove the old kvno right away and accept that users have to kinit again.

Delete the backup copies of the keytab when you are done; they are as sensitive as the live file.

A rotation checklist

  1. Back up /etc/krb5.keytab on each host; note getprinc kvno and maximum ticket life.
  2. NFS server: kadmin ktadd -k /etc/krb5.keytab nfs/... host/... on the server itself.
  3. Verify with klist -ke and kvno -k; no gssproxy restart was needed in the lab.
  4. Each client: k5srvutil change or kadmin ktadd for its host/ (and nfs/) key on the client itself; verify with kinit -k.
  5. Wait at least the maximum ticket lifetime (24 hours by default) plus clock skew.
  6. Clean up: ktremove ... old or k5srvutil delold; if you used -keepold, also purgekeys.
  7. Verify again and delete the backups.

What was tested and what was not

Tested with the AlmaLinux 10 packages (krb5-server 1.21.3, gssproxy 0.9.2, nfs-utils 2.8.3), run without root on a test machine with a private KDC and kadmind on high ports, no systemd: ktadd of nfs/ and host/ in one command, adding a new kvno next to the old one; klist -ke with both kvnos; getprinc showing only the new key; a ticket for the old kvno accepted by a GSS-API server while both kvnos were in the keytab, and refused after ktremove ... old; a fresh ticket getting the new kvno; a keytab without the new kvno; kvno -k; ktremove with old and with a number; ktutil rkt/list/delent; cpw -randkey -keepold, ktadd -norandkey (local and remote), purgekeys; kinit -k with old and new client keytabs; k5srvutil list/change/delold through kadmind; remote kadmin ktadd; a pre-rotation machine TGT still working; and gssproxy using the changed keytab without a restart. All error messages in this post come from these runs.

Not tested: a real kernel NFS export and mount, so what happens to active mounts during rotation; rpc.gssd, rpc.idmapd and nfs-server running under systemd, and systemctl restart rpc-gssd / reload gssproxy; the machine ticket files in /tmp; copying keytabs between hosts with scp, and SELinux labels (restorecon); default port 749 and firewalld; FreeIPA/IdM (which uses ipa-getkeytab instead) and Active Directory. Try the whole sequence on a test server and client before you rotate keys in production.

Where to go next

Put this rotation on a schedule (for example yearly, and right away whenever a keytab may have leaked), and keep the troubleshooting table in your runbook. If you have not yet, add a replica KDC so that key changes and NFS logins do not depend on one server. For the basics of keytab files, see Create and Manage Kerberos Keytabs. The next post in this series covers Secure NFS with Active Directory Kerberos.

Leave a Reply

Your email address will not be published. Required fields are marked *