Kerberos provides single sign-on authentication for SSH, but when it fails, you see errors like:
$ ssh user@server.example.com
Permission denied (gssapi-with-mic,publickey,password)Or specifically:
$ ssh user@server.example.com
debug1: Attempting GSSAPI authentication...
debug1: GSSAPI authentication failed: Server not found in Kerberos databaseThis guide covers Kerberos authentication issues specific to SSH.
Understand Kerberos SSH Flow
For Kerberos SSH to work:
- 1.You have a Kerberos ticket from your realm's KDC
- 2.The SSH server has a service principal (host/server.example.com@REALM)
- 3.Your ticket can authenticate to that service principal
- 4.SSHD is configured to accept GSSAPI
Verify Your Kerberos Ticket
First, check your current ticket:
klistHealthy output:
``` Ticket cache: FILE:/tmp/krb5cc_1000 Default principal: admin@CORP.EXAMPLE.COM
Valid starting Expires Service principal 04/03/2026 10:00:00 04/03/2026 18:00:00 krbtgt/CORP.EXAMPLE.COM@CORP.EXAMPLE.COM renew until 04/10/2026 10:00:00 ```
If empty or expired:
kinit admin@CORP.EXAMPLE.COMEnter your Kerberos password. Verify:
klistCheck Ticket Cache Location
SSH needs to find your credential cache:
echo $KRB5CCNAMEIf unset:
ls -la /tmp/krb5cc_*Set the environment variable:
export KRB5CCNAME=FILE:/tmp/krb5cc_1000Make it permanent in ~/.bashrc:
export KRB5CCNAME=FILE:/tmp/krb5cc_$(id -u)Verify Kerberos Configuration
Check /etc/krb5.conf:
cat /etc/krb5.confMust include:
``` [libdefaults] default_realm = CORP.EXAMPLE.COM dns_lookup_realm = false dns_lookup_kdc = true ticket_lifetime = 24h forwardable = true
[realms] CORP.EXAMPLE.COM = { kdc = kdc01.corp.example.com kdc = kdc02.corp.example.com admin_server = kdc01.corp.example.com }
[domain_realm] .corp.example.com = CORP.EXAMPLE.COM corp.example.com = CORP.EXAMPLE.COM ```
Test Kerberos Independently
Before debugging SSH, test Kerberos directly:
kinit admin@CORP.EXAMPLE.COM
klistGet a service ticket:
kvno host/server.corp.example.com@CORP.EXAMPLE.COMThis tests if you can authenticate to the SSH service principal.
If kvno fails:
kvno: Server not found in Kerberos database while getting credentials for host/server.corp.example.comThe service principal doesn't exist.
Check Server Service Principal
On the KDC or using kadmin:
kadmin -q "listprincs" | grep host/serverIf missing, create it:
kadmin -q "addprinc -randkey host/server.corp.example.com@CORP.EXAMPLE.COM"Extract keytab for the server:
kadmin -q "ktadd host/server.corp.example.com@CORP.EXAMPLE.COM"Copy the keytab to the server:
scp keytab server:/etc/krb5.keytabVerify Server Keytab
On the SSH server:
klist -k /etc/krb5.keytabShould show:
Keytab name: FILE:/etc/krb5.keytab
KVNO Principal
---- ----------
3 host/server.corp.example.com@CORP.EXAMPLE.COMCheck Keytab Permissions
ls -la /etc/krb5.keytabFix permissions:
sudo chown root:root /etc/krb5.keytab
sudo chmod 600 /etc/krb5.keytabEnable GSSAPI in SSHD
On the server:
sudo grep GSSAPIAuthentication /etc/ssh/sshd_configEnable it:
sudo sed -i 's/^#*GSSAPIAuthentication.*/GSSAPIAuthentication yes/' /etc/ssh/sshd_config
sudo systemctl restart sshdAlso enable:
sudo sed -i 's/^#*GSSAPICleanupCredentials.*/GSSAPICleanupCredentials yes/' /etc/ssh/sshd_config
sudo sed -i 's/^#*GSSAPIKeyExchange.*/GSSAPIKeyExchange yes/' /etc/ssh/sshd_config
sudo systemctl restart sshdEnable GSSAPI in SSH Client
In ~/.ssh/config:
Host *.corp.example.com
GSSAPIAuthentication yes
GSSAPIDelegateCredentials yes
GSSAPIKeyExchange yesGSSAPIDelegateCredentials forwards your ticket to the server.
Debug SSH Kerberos
Verbose SSH:
ssh -vvv admin@server.corp.example.com 2>&1 | tee kerberos_debug.log
grep -i gss kerberos_debug.logLook for:
debug3: send SSH2_MSG_KEXINIT_KEXGSS_HOSTKEY
debug1: Offering GSSAPI proposal: gss-gex-sha1-krb5,gss-mic-sha1-krb5If it shows "Permission denied" after GSSAPI offer, check server-side logs.
Check Server Logs
On the server:
sudo journalctl -u sshd -fConnect and watch:
Apr 3 10:15:22 server sshd[12345]: gssapi-with-mic-krb5: Miscellaneous failure
Apr 3 10:15:22 server sshd[12345]: Permission denied for user admin from 192.168.1.50Check Clock Synchronization
Kerberos requires clocks within 5 minutes:
```bash # Check client time date
# Check server time ssh server 'date' ```
If more than 5 minutes apart:
# Sync both to NTP
sudo systemctl restart chronyd
# or
sudo systemctl restart ntpdHandle Cross-Realm Authentication
If your ticket is from a different realm:
klist
# Shows: Default principal: admin@OTHER.REALM.COMBut server is in CORP.EXAMPLE.COM:
You need a cross-realm trust or ticket for the target realm:
kinit -S host/server.corp.example.com@CORP.EXAMPLE.COM admin@OTHER.REALM.COMFix Principal-to-Username Mapping
If Kerberos principal differs from SSH username:
# Kerberos principal: alice@CORP.EXAMPLE.COM
# SSH username: alice_adminCreate .k5login:
echo "alice@CORP.EXAMPLE.COM" > ~/.k5login
chmod 600 ~/.k5loginOr configure mapping in sshd_config:
sudo grep -i authusers /etc/ssh/sshd_configAdd:
GSSAPIAuthUsers yes
AuthorizedPrincipalsFile /etc/ssh/auth_principals/%uCreate principals file:
sudo mkdir -p /etc/ssh/auth_principals
echo "alice@CORP.EXAMPLE.COM" | sudo tee /etc/ssh/auth_principals/alice_adminHandle Hostname Mismatch
Kerberos principal hostname must match SSH server hostname:
# Check server's actual hostname
hostname -fIf hostname is server.internal.corp.example.com but principal is host/server.corp.example.com:
Create principal matching hostname:
kadmin -q "addprinc -randkey host/server.internal.corp.example.com@CORP.EXAMPLE.COM"Or set canonical hostname in client config:
Host server.corp.example.com
CanonicalizeHostname yes
CanonicalDomains internal.corp.example.com corp.example.comCheck DNS and Service Records
Kerberos uses DNS for discovery:
dig _kerberos._tcp.corp.example.com SRV
dig _kpasswd._tcp.corp.example.com SRVIf missing, add to krb5.conf manually:
[realms]
CORP.EXAMPLE.COM = {
kdc = kdc01.corp.example.com:88
admin_server = kdc01.corp.example.com:749
}Test with Explicit Principal
Specify your principal:
kinit -p admin@CORP.EXAMPLE.COM
ssh -o GSSAPIAuthentication=yes admin@server.corp.example.comForward Ticket to Server
If you need to SSH further from the server:
ssh -o GSSAPIDelegateCredentials=yes admin@server.corp.example.comOn the server:
klistShould show forwarded credentials.
Resolution Checklist
- 1.Verify Kerberos ticket:
klist - 2.Get fresh ticket:
kinit principal@REALM - 3.Set
KRB5CCNAMEenvironment variable - 4.Check
/etc/krb5.confconfiguration - 5.Verify service principal exists:
kadmin -q "listprincs" - 6.Check server keytab:
klist -k /etc/krb5.keytab - 7.Fix keytab permissions
- 8.Enable GSSAPI in
sshd_config - 9.Enable GSSAPI in
~/.ssh/config - 10.Synchronize clocks
- 11.Use
.k5loginfor principal mapping - 12.Verify hostname matches principal
Kerberos SSH errors usually stem from missing service principals, expired tickets, or clock synchronization. Start by verifying your ticket and the server's principal configuration.