SkillPilotAI

kinit, klist, kdestroy, kvno, ldapsearch

Kerberos and LDAP from the command line: kinit gets a TGT from the KDC, klist shows tickets, kdestroy deletes them, kvno checks a service key version, and ldapsearch queries an LDAP directory (with simple or SASL/GSSAPI bind). These are the first tools you reach for when an AD/LDAP login or SSO fails.

162.1 Why is it used?

  • kinit: log in to a Kerberos realm once and get a TGT (ticket-granting ticket), so services need no password.
  • klist / kdestroy: see which tickets you hold (lifetime, flags, enctypes) and clean them up.
  • kvno: get a service ticket and print its key version number; kvno -k verifies a server keytab.
  • ldapsearch: find users, groups and attributes in OpenLDAP / Active Directory, test binds, filters and controls.
  • Linux uses MIT Kerberos (krb5-user) + OpenLDAP clients (ldap-utils); macOS has Heimdal kinit/klist/kdestroy built in.

162.2 How it works

  • Lab: client 192.168.182.20, dc 192.168.182.10 running MIT krb5kdc (:88, realm LAB.LOCAL) and slapd (:389).
  • kinit sends an AS-REQ; the KDC returns a TGT (krbtgt/LAB.LOCAL) that is stored in the cache (FILE:/tmp/krb5cc_0).
  • For a service, the client shows the TGT and gets a service ticket (e.g. ldap/dc.lab.local).
  • With -Y GSSAPI, ldapsearch sends only that service ticket; slapd verifies it with its own keytab. No password travels.
  • An LDAP search request carries base, scope, filter and attributes; slapd returns entries and referrals.
Kerberos flow: kinit, ticket, GSSAPI bind
  1. 1.kinit asha: AS-REQ to KDC 192.168.182.10:88 (cname asha, sname krbtgt/LAB.LOCAL)

  2. 2.KDC returns the TGT, saved in the client cache

  3. 3.ldapsearch -Y GSSAPI shows the TGT and asks for ldap/dc.lab.local

  4. 4.KDC returns the service ticket

  5. 5.SASL bind to slapd :389 with the ticket (no password)

  6. 6.slapd verifies with its keytab: dn uid=asha,ou=people,dc=lab,dc=local

This is why a GSSAPI bind never sends the password to LDAP

162.3 kinit (MIT)

  • No ticket yet: klist says "No credentials cache found". A wrong password gives "Password incorrect".
  • Default TGT here is valid for 10 hours with a renew-until time.
  • -V verbose, -l 2h lifetime, -r 3d renewable life, -f forwardable (F flag), -p proxiable (P flag).
  • -R renews the TGT without a password; -F / -A turn off forwardable / addresses.
  • -S kadmin/changepw gets a service ticket instead of a TGT, so later kvno fails.
  • -c FILE uses a separate cache; -n asks for an anonymous ticket (anonymous PKINIT is not enabled in the lab).
Terminal
klistkinit ashaklistkdestroykinit -V -l 2h -r 3d -f -p ashaklist -f
Output
$ klistklist: No credentials cache found (filename: /tmp/krb5cc_0)$ kinit ashaPassword for asha@LAB.LOCAL:kinit: Password incorrect while getting initial credentialsTicket cache: FILE:/tmp/krb5cc_0Default principal: asha@LAB.LOCAL Valid starting     Expires            Service principal11/09/26 07:59:27  11/09/26 17:59:27  krbtgt/LAB.LOCAL@LAB.LOCAL	renew until 11/10/26 07:59:27$ kinit -V -l 2h -r 3d -f -p ashaUsing default cache: /tmp/krb5cc_0Using principal: asha@LAB.LOCALAuthenticated to Kerberos v5$ klist -f11/09/26 07:59:29  11/09/26 09:59:29  krbtgt/LAB.LOCAL@LAB.LOCAL	renew until 11/12/26 07:59:29, Flags: FPRIA
Terminal
sleep 3; kinit -R; klist -fkinit -S kadmin/changepw asha; klistkvno host/srv.lab.localkinit -n
Output
$ sleep 3; kinit -R; klist -fValid starting     Expires            Service principal11/09/26 07:59:35  11/09/26 09:59:35  krbtgt/LAB.LOCAL@LAB.LOCAL	renew until 11/12/26 07:59:29, Flags: FPRIAT$ kinit -S kadmin/changepw asha; klist11/09/26 07:59:40  11/09/26 08:04:40  kadmin/changepw@LAB.LOCAL$ kvno host/srv.lab.localkvno: Matching credential not found (filename: /tmp/krb5cc_0) while getting credentials for host/srv.lab.local@LAB.LOCAL$ kinit -nkinit: Client 'WELLKNOWN/ANONYMOUS@LAB.LOCAL' not found in Kerberos database while getting initial credentials
  • Other kinit options: -s 1h postdated (validate with -v), -k -t KEYTAB keytab login, -T CCACHE FAST armor, -X ... PKINIT, --request-pac for AD.

162.4 kvno and keytabs

  • kvno SPN gets a service ticket and prints its key version (kvno = 1).
  • -q quiet on success, -e ETYPE asks for a session key type, -c another cache.
  • A wrong SPN gives "Server ... not found in Kerberos database".
  • --u2u CCACHE gets a user-to-user ticket (kvno = 0).
  • Keytab: klist -k -t -e shows kvno and enctypes (never keys); kinit -k -t logs in a service without a password; kvno -k verifies the entry.
Terminal
kvno host/srv.lab.localkvno -e aes128-cts-hmac-sha1-96 HTTP/web.lab.localkvno nosuch/x.lab.localklist -k -t -e /root/web.keytabkinit -k -t /root/web.keytab HTTP/web.lab.localkvno -k /root/web.keytab HTTP/web.lab.localkvno -k /root/web.keytab host/srv.lab.local
Output
$ kvno host/srv.lab.localhost/srv.lab.local@LAB.LOCAL: kvno = 1$ kvno -e aes128-cts-hmac-sha1-96 HTTP/web.lab.localHTTP/web.lab.local@LAB.LOCAL: kvno = 2$ kvno nosuch/x.lab.localkvno: Server nosuch/x.lab.local@LAB.LOCAL not found in Kerberos database while getting credentials for nosuch/x.lab.local@LAB.LOCAL$ klist -k -t -e /root/web.keytabKeytab name: FILE:/root/web.keytabKVNO Timestamp         Principal---- ----------------- ---------------------------   2 11/09/26 07:59:11 HTTP/web.lab.local@LAB.LOCAL (aes256-cts-hmac-sha1-96)   2 11/09/26 07:59:11 HTTP/web.lab.local@LAB.LOCAL (aes128-cts-hmac-sha1-96)$ kvno -k /root/web.keytab HTTP/web.lab.localHTTP/web.lab.local@LAB.LOCAL: kvno = 2, keytab entry valid$ kvno -k /root/web.keytab host/srv.lab.localhost/srv.lab.local@LAB.LOCAL: kvno = 1, keytab entry invalidkvno: Wrong principal in request while decrypting ticket for host/srv.lab.local@LAB.LOCAL
  • More kvno options: -S HTTP web.x.com builds sname/host, -I / -U S4U2Self, -P S4U2Proxy, --cached-only (no KDC), --no-store, --out-cache CC.

162.5 klist and kdestroy

  • klist -e shows session key and ticket enctypes; klist -s says only via exit code if a valid ticket exists (good in scripts).
  • With KRB5CCNAME=DIR:/tmp/kcc each principal gets its own cache; klist -l lists caches, klist -A shows all.
  • kdestroy -A deletes all caches, -c one cache, -p one principal, -q only stops the beep.
  • klist -K prints real key values: sensitive, never run it casually.
Terminal
klist -eklist -s && echo validexport KRB5CCNAME=DIR:/tmp/kcckinit asha; kinit raviklist -lkdestroy -A; klist -l
Output
$ klist -s && echo validvalid$ klist -lPrincipal name                 Cache name--------------                 ----------ravi@LAB.LOCAL                 DIR::/tmp/kcc/tktfaCDNpasha@LAB.LOCAL                 DIR::/tmp/kcc/tkt$ kdestroy -A; klist -lPrincipal name                 Cache name--------------                 ----------
klist -f flagMeaningklist -f flagMeaning
Fforwardablefforwarded
Pproxiablepproxy
Dpostdateabledpostdated
RrenewableIinitial
ApreauthTtransit checked
Hhardware authaanonymous

162.6 macOS Heimdal kinit, klist, kdestroy

  • Syntax from Apple man pages (not run in the lab, no example output).
  • Long options: --lifetime=10h, --renewable-life, --renew, --keytab=FILE, --use-keytab, --server=PRINC.
  • kinit principal command runs that command with a fresh cache.
  • -e enctypes (e.g. aes256-cts-hmac-sha1-96), -a extra addresses (public IP behind NAT), -A no addresses.
  • Heimdal klist -s / -t / --test only tests, -v shows etype and kvno, -l lists caches; kdestroy -A / --all deletes all.
TaskLinux (MIT)macOS (Heimdal)
Lifetimekinit -l 2hkinit --lifetime=10h
Renewkinit -Rkinit -R / --renew
Keytab loginkinit -k -t FILEkinit -t FILE / -k
Test for ticketklist -sklist -s / -t / --test
List cachesklist -lklist -l / --list-caches
Delete allkdestroy -Akdestroy -A / --all

162.7 ldapsearch: scope, base and filters

  • -b base, -s base | one | sub | children; sub is default, children = descendants without the base.
  • -s base -b '' reads the root DSE: namingContexts, supportedSASLMechanisms, supportedControl.
  • Filters are prefix form: & AND, | OR, ! NOT.
  • Attribute list: 1.1 = DN only, '*' user attributes, '+' operational attributes (entryUUID, createTimestamp).
  • The ou=partners referral points to 192.168.182.30; ldapsearch shows it but never contacts that server.
Terminal
DC=192.168.182.10; B=dc=lab,dc=localLS="ldapsearch -x -H ldap://$DC"$LS -s base -b '' -LLL namingContexts supportedSASLMechanisms supportedControl$LS -LLL -s one -b $B dn$LS -LLL -s sub -b $B '(cn=A*)' cn$LS -b $B -LLL '(&(objectClass=inetOrgPerson)(title=Developer))' uid$LS -b $B -LLL '(uid=asha)' '+'
Output
dn:namingContexts: dc=lab,dc=localsupportedControl: 2.16.840.1.113730.3.4.9supportedControl: 1.2.840.113556.1.4.473...supportedSASLMechanisms: GSS-SPNEGOsupportedSASLMechanisms: GSSAPI$ ... -s one -b $B dndn: ou=groups,dc=lab,dc=local# refldap://192.168.182.30/ou=partners,dc=lab,dc=local??base$ ... -s sub -b $B '(cn=A*)' cncn: Asha Vermacn: Arjun Mehta$ ... '(&(objectClass=inetOrgPerson)(title=Developer))' uiddn: uid=ravi,ou=people,dc=lab,dc=localuid: ravidn: uid=neha,ou=people,dc=lab,dc=localuid: nehadn: uid=priya,ou=people,dc=lab,dc=localuid: priya$ ... '(uid=asha)' '+'structuralObjectClass: inetOrgPersonentryUUID: 77df9dc2-66e0-479d-9f64-bf5c4caa89f5creatorsName: cn=admin,dc=lab,dc=localcreateTimestamp: 20261109075918ZentryDN: uid=asha,ou=people,dc=lab,dc=localhasSubordinates: FALSE
ScopeWhat it returns (lab)
-s baseOnly the base entry itself (or root DSE with -b '')
-s oneDirect children: ou=groups, ou=people (+ partners referral)
-s childrenAll descendants without the base: the 6 users
-s sub (default)Base + whole subtree

162.8 ldapsearch output control

  • Default is extended LDIF with comments and a search result footer; -L = LDIFv1, -LLL = clean (best for scripts).
  • -A attribute names only, -u adds a ufn (friendly DN), -t writes binary values (jpegPhoto) to temp files.
  • -z 2 size limit gives "Size limit exceeded (4)" and exit 4; -l 5 time limit; -S sn sorts on the client.
  • -o ldif_wrap=no stops wrapping at 76 columns; -n -v shows the plan without searching.
Terminal
$LS -LLL -z 2 -b ou=people,$B '(objectClass=person)' uid$LS -LLL -o ldif_wrap=no -b $B '(uid=asha)' description
Output
dn: uid=asha,ou=people,dc=lab,dc=localuid: ashadn: uid=neha,ou=people,dc=lab,dc=localuid: nehaSize limit exceeded (4)(exit 4)$ ... -LLL -o ldif_wrap=no ... descriptiondescription: Asha manages the core routers, the firewalls and the VPN gateway of the Delhi office

162.9 ldapsearch bind: simple, TLS and SASL

  • -x simple bind with -D binddn and -w password (visible in ps) / -W prompt / -y file.
  • Wrong password: "Invalid credentials (49)". -y uses the whole file, so a trailing newline from echo breaks it (use printf).
  • -P 2 is rejected: "historical protocol version requested, use LDAPv3".
  • No TLS in the lab: -ZZ (StartTLS required) stops; -Z warns and continues in plain text (risky); ldaps:// gives "Can't contact LDAP server (-1)".
  • Referral entry gives "Referral (10)"; -M (ManageDsaIT) shows it as a normal object.
  • SASL: -Y EXTERNAL over ldapi:/// uses the Unix uid; -Y GSSAPI needs a ticket first; DIGEST-MD5 without its plugin: "No worthy mechs found".
Terminal
$LS -D $D -w wrong-pass ...$LS -ZZ -LLL -b $B '(uid=asha)' cnkdestroy; ldapsearch -Y GSSAPI -N -H ldap://dc.lab.local -LLL -b $B '(uid=asha)' cnkinit asha; ldapsearch -Y GSSAPI -N ...ldapwhoami -Q -Y GSSAPI -N -H ldap://dc.lab.local
Output
ldap_bind: Invalid credentials (49)$ ... -ZZ -LLL -b $B '(uid=asha)' cnldap_start_tls: Protocol error (2)	additional info: unsupported extended operation(exit 1)$ kdestroy; ldapsearch -Y GSSAPI -N ...ldap_sasl_interactive_bind: Local error (-2)	additional info: SASL(-1): generic failure: GSSAPI Error:  Miscellaneous failure (see text) (get-principal lstat(/tmp/krb5cc_0))$ kinit asha; ldapsearch -Y GSSAPI -N ...SASL username: asha@LAB.LOCALSASL SSF: 56dn: uid=asha,ou=people,dc=lab,dc=localcn: Asha Verma$ ldapwhoami -Q -Y GSSAPI -N -H ldap://dc.lab.localdn:uid=asha,ou=people,dc=lab,dc=local

162.10 Controls: -e (general) and -E (search)

  • A leading ! makes a control critical: the operation fails if the server does not support it.
  • -e manageDSAit returns the referral entry and its ref attribute; -e 'assert=(filter)' gives "Assertion Failed (122)" on no match.
  • -E pr=2/noprompt pages results 2 at a time with a cookie after every page.
  • -E '!sss=sn' fails with "Inappropriate matching (18)" (no ordering rule); '!sss=-sn:2.5.13.3' sorts descending.
  • AD-only Show Deleted OID 1.2.840.113556.1.4.417 as critical: "Critical extension is unavailable (12)".
Terminal
$LS -LLL -E pr=2/noprompt -b ou=people,$B '(objectClass=person)' uid$LS -LLL -E '!sss=-sn:2.5.13.3' -b ou=people,$B '(objectClass=person)' sn
Output
uid: ashauid: ravi# pagedresults: cookie=BQAAAAAAAAA=uid: nehauid: arjun# pagedresults: cookie=BwAAAAAAAAA=uid: priyauid: kabir# pagedresults: cookie=$ ... -E '!sss=-sn:2.5.13.3' ... snsn: Vermasn: Singhsn: Nairsn: Mehtasn: Kumarsn: Khan# sortResult: (0) Success
LDAP errorCodeCause in the lab
Size limit exceeded4-z 2 smaller than the result set
Invalid credentials49Wrong password, or newline in -y file
Protocol error2-P 2, or StartTLS on a server without TLS
Referral10Base points to a referral entry (use -M)
Assertion Failed122-e assert filter did not match
Inappropriate matching18sss on an attribute with no ordering rule
Critical extension is unavailable12Unsupported control sent with !

162.11 Common mistakes

  • Using kinit -S and then expecting kvno to work: you have no TGT, run a plain kinit.
  • Writing the -y password file with echo (adds a newline): use printf %s.
  • Using -Z instead of -ZZ: on failure it silently continues in plain text.
  • Passing -w on shared machines: the password shows in the process list; use -W or -y.
  • Thinking a GSSAPI bind sends your password to LDAP: it sends only the service ticket.

162.12 Interview tips

  • kvno gets a service ticket and shows the key version; if it does not match the server keytab, the service cannot decrypt the ticket and login fails. Verify with kvno -k.
  • Know the flow: AS-REQ (kinit) -> TGT -> TGS-REQ -> service ticket -> AP-REQ to the service.
  • LDAP search = base + scope + filter + attributes; filters use prefix &, |, !.
  • Ports: Kerberos 88, LDAP 389, LDAPS 636, AD Global Catalog 3268.