An NFS export that accepts only numeric client user IDs cannot tell whether a client is honestly representing the user behind each request. Kerberos-backed NFS moves that trust decision to RPCSEC_GSS, so the server accepts file operations only after Kerberos credentials have negotiated a security flavor such as krb5p.
The server side of the setup needs an nfs/<server-fqdn> service principal, a root-owned keytab entry, and an export rule whose sec= option excludes sys. The client still needs matching realm configuration and Kerberos-capable NFS tools, but the export is not protected until the active server table shows the Kerberos flavor.
Use one fully qualified server name for the service principal, export rule, and mount source. In the sample environment, files.example.net is the NFS server, EXAMPLE.NET is the Kerberos realm, and sec=krb5p requires authentication, integrity protection, and encrypted file data for the export.
Related: How to create an NFS export
Related: How to configure NFS over TLS
$ hostname --fqdn files.example.net
The NFS service principal must match this fully qualified name. Avoid Kerberized mounts by raw IP address or by a short alias that resolves differently on clients.
$ sudo apt install --assume-yes krb5-user nfs-kernel-server
Ubuntu and Debian use krb5-user for Kerberos client utilities and nfs-kernel-server for server exports. Use the equivalent package names on another distribution.
$ kadmin -p admin/admin -q "addprinc -randkey nfs/files.example.net@EXAMPLE.NET" Authenticating as principal admin/admin with password. Principal "nfs/files.example.net@EXAMPLE.NET" created.
Run the equivalent realm-management command when the KDC is FreeIPA, Active Directory, or another identity system.
$ sudo kadmin -p admin/admin -q "ktadd -k /etc/krb5.keytab nfs/files.example.net@EXAMPLE.NET" Authenticating as principal admin/admin with password. Entry for principal nfs/files.example.net@EXAMPLE.NET with kvno 2, encryption type aes256-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab. Entry for principal nfs/files.example.net@EXAMPLE.NET with kvno 2, encryption type aes128-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
/etc/krb5.keytab is a persistent server secret. Keep it readable only by root and rotate the principal key if the file is copied outside the server's credential-control process.
$ sudo chmod 600 /etc/krb5.keytab
$ sudo klist -k /etc/krb5.keytab Keytab name: FILE:/etc/krb5.keytab KVNO Principal ---- -------------------------------------------------------------------------- 2 nfs/files.example.net@EXAMPLE.NET 2 nfs/files.example.net@EXAMPLE.NET
$ findmnt -T /srv/nfs/projects TARGET SOURCE FSTYPE OPTIONS /srv/nfs/projects /dev/mapper/vg0-projects xfs rw,relatime
Some test, overlay, and container filesystems cannot be exported by the kernel NFS server even when the export syntax is valid.
$ sudo install -d -o root -g root -m 0755 /etc/exports.d
$ sudoedit /etc/exports.d/projects.exports
exportfs reads files in /etc/exports.d only when their names end in .exports.
/srv/nfs/projects 192.0.2.0/24(rw,sync,no_subtree_check,sec=krb5p,root_squash)
sec=krb5p requires authentication, integrity protection, and payload privacy. Use sec=krb5i only when integrity without encryption is acceptable, and keep sec=sys out of this selector when clients must authenticate with Kerberos.
$ sudo systemctl restart nfs-server
Ubuntu packages install rpc-svcgssd.service for server-side GSS handling and start it through nfs-server.service when /etc/krb5.keytab exists.
$ sudo exportfs -ra
No output means exportfs accepted the saved export definitions. Fix any syntax, missing-path, or unsupported-filesystem error before testing from a client.
Related: How to reload NFS exports
$ sudo exportfs -v /srv/nfs/projects 192.0.2.0/24(sync,wdelay,hide,no_subtree_check,sec=krb5p,rw,root_squash,no_all_squash)
The active table should show sec=krb5p, sec=krb5i, or sec=krb5 for the protected selector, not only sec=sys.
Related: How to list NFS exports on a server
$ sudo systemctl is-active rpc-gssd active
rpc.gssd uses machine credentials from /etc/krb5.keytab for root-initiated mounts and user credential caches for per-user file access.
Related: How to mount a Kerberos-secured NFS export
$ kinit alice Password for alice@EXAMPLE.NET:
$ sudo mkdir --parents /mnt/projects
Files already inside /mnt/projects become hidden while the NFS filesystem is mounted there.
$ sudo mount -t nfs -o vers=4.2,sec=krb5p files.example.net:/srv/nfs/projects /mnt/projects
Use sec=krb5i or sec=krb5 here only when the server export allows the same flavor.
Related: How to mount an NFS export on Linux
$ findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS /mnt/projects TARGET SOURCE FSTYPE OPTIONS /mnt/projects files.example.net:/srv/nfs/projects nfs4 rw,relatime,vers=4.2,sec=krb5p,proto=tcp ##### snipped #####
$ touch /mnt/projects/kerberos-check.txt
$ klist Ticket cache: FILE:/tmp/krb5cc_1000 Default principal: alice@EXAMPLE.NET Valid starting Expires Service principal 07/05/2026 10:15:01 07/05/2026 20:15:01 krbtgt/EXAMPLE.NET@EXAMPLE.NET 07/05/2026 10:16:12 07/05/2026 20:15:01 nfs/files.example.net@EXAMPLE.NET
$ rm /mnt/projects/kerberos-check.txt
$ sudo umount /mnt/projects