Configure Kerberos Authentication for SFTP#

Authentication with Kerberos allows you to connect to a remote server without a password using the ticket you already obtained when logging in to your organization’s realm with kinit or with your account on the Mac. The ticket is presented to the server using the SSH authentication method gssapi-with-mic, the equivalent of ssh -o GSSAPIAuthentication=yes.

Important

  • Cyberduck 9.7.0 or later required

  • Mountain Duck 6.0.0 or later required

Authentication with Kerberos is attempted after public key authentication and before prompting for a password when no password is saved for the bookmark. Without a valid ticket the method is skipped and the login continues with the next authentication method offered by the server. Kerberos authentication can be disabled with the hidden configuration option ssh.authentication.gssapi.enable.

Requirements#

  • The server running OpenSSH is configured with GSSAPIAuthentication yes in sshd_config and has a keytab with the service principal host/server.example.com@EXAMPLE.COM for its fully qualified hostname. Refer to your administrator.

  • Your principal such as user@EXAMPLE.COM is allowed to log in to the account on the server. By default the principal user@EXAMPLE.COM maps to the account user. Additional principals are listed in ~/.k5login of the account on the server.

  • The Key Distribution Center (KDC) of the realm of the server is found in the Kerberos configuration or can be looked up in DNS. The realm of the server is determined from the Kerberos configuration, the realm in the bookmark or else is assumed to be the realm of your ticket.

  • On Windows, MIT Kerberos for Windows is installed to obtain the ticket.

Setup#

  1. Obtain a ticket for your principal. Enter the password of your Kerberos account when prompted.

    kinit user@EXAMPLE.COM
    

    Tip

    Tickets obtained with Ticket Viewer.app in /System/Library/CoreServices/Applications or when logging in to a Mac bound to a directory service with Kerberos are used as well.

  2. Verify a ticket for the realm is listed and has not expired.

    klist
    
  3. Verify the setup with OpenSSH before connecting with Cyberduck. Use the fully qualified hostname of the server.

    ssh -o GSSAPIAuthentication=yes -o PreferredAuthentications=gssapi-with-mic user@server.example.com
    

    A service ticket for host/server.example.com@EXAMPLE.COM is now listed with klist.

  4. Add a new Bookmark in Cyberduck or Mountain Duck. Enter the fully qualified hostname server.example.com in Server and your account in Username. You do not need to set a value for Password or select a SSH Private Key.

    Warning

    The hostname must match the service principal in the keytab of the server. Connecting using an IP address or a short hostname may fail when it cannot be resolved to the fully qualified name.

  5. Optionally enter the realm such as EXAMPLE.COM in Kerberos Realm in the More Options tab of the bookmark when the server belongs to a different realm than your ticket.

  6. Connect to the server. No prompt is displayed when the ticket is accepted.

Kerberos Realm per Bookmark#

The service principal of the server such as host/server.example.com@EXAMPLE.COM is composed from the hostname and the realm of the server. The realm is determined in the following order.

  1. The realm set in Kerberos Realm of the bookmark. The field is found in the More Options tab on macOS.

  2. The realm the hostname is mapped to in [domain_realm] or else the default_realm of the Kerberos configuration.

  3. The realm of your ticket such as EXAMPLE.COM for the principal user@EXAMPLE.COM.

Set the realm in the bookmark when the server belongs to a different realm than your ticket and no Kerberos configuration maps the hostname to it. The KDC of the realm is looked up in [realms] of the Kerberos configuration or from DNS SRV records. The realm only applies to this connection and the Kerberos configuration is not changed.

The realm is saved in the bookmark as the property ssh.authentication.gssapi.realm and can also be set in a .duck bookmark file.

Kerberos Configuration#

A Kerberos configuration is optional when the realm of the server matches the realm of your ticket and the KDC can be looked up from DNS SRV records. The Kerberos configuration is read from

  • macOS: ~/Library/Preferences/edu.mit.Kerberos, /Library/Preferences/edu.mit.Kerberos or /etc/krb5.conf

  • Linux: /etc/krb5.conf

  • Windows: krb5.ini in the Windows directory such as C:\Windows\krb5.ini

A minimal configuration for the realm EXAMPLE.COM looks like

[libdefaults]
    default_realm = EXAMPLE.COM

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

[domain_realm]
    .example.com = EXAMPLE.COM

Omit the [realms] section and add dns_lookup_kdc = true to [libdefaults] to look up the KDC from _kerberos._tcp and _kerberos._udp DNS SRV records of the realm instead.

The following hidden configuration options can be set for all connections or for a single bookmark.

Option

Description

ssh.authentication.gssapi.enable

Set to false to disable Kerberos authentication. Defaults to true.

ssh.authentication.gssapi.ticketcache

Path to a credentials cache file to read the ticket from instead of the default cache. Obtain a ticket written to the file with kinit -c /path/to/file user@EXAMPLE.COM.

ssh.authentication.gssapi.realm

Realm of the server set with Kerberos Realm in the bookmark. Refer to Kerberos Realm per Bookmark.

ssh.authentication.gssapi.mit

Windows only. Set to false to not copy the ticket from the credentials cache of MIT Kerberos for Windows. Defaults to true. Has no effect when MIT Kerberos for Windows is not installed.

Example to disable Kerberos authentication for Cyberduck on macOS.

defaults write ch.sudo.cyberduck ssh.authentication.gssapi.enable false

Connection Profiles#

The Kerberos Realm field is shown in the bookmark for SFTP connections. Hide it for a connection profile based on SFTP by setting Kerberos Configurable to false.

Require Public Key and Kerberos Authentication#

Servers can require authentication with both a private key and a Kerberos ticket with AuthenticationMethods publickey,gssapi-with-mic in sshd_config. Select the private key in SSH Private Key of the bookmark. After the key has been accepted, login completes with the Kerberos ticket.

Troubleshooting#

Warning

When you are prompted for a password instead, no ticket was found or the server did not accept it. Verify with klist that the ticket for the realm has not expired and obtain a new ticket with kinit otherwise. Verify the login with ssh -v -o GSSAPIAuthentication=yes user@server.example.com which prints the reason why the method failed.

Warning

The message Server not found in Kerberos database printed by ssh -v indicates no service principal matches the hostname used to connect. Connect using the fully qualified hostname matching the keytab of the server.

Warning

Authentication fails when the clock of your computer differs by more than five minutes from the KDC or the server. Enable Set time and date automatically in System Settings → General → Date & Time.

Warning

On Windows, when you are prompted for a password, verify klist.exe of MIT Kerberos for Windows lists a ticket granting ticket krbtgt/EXAMPLE.COM@EXAMPLE.COM for your realm. MIT Kerberos for Windows installed in a folder other than MIT\Kerberos\bin in Program Files is not found.

Note

The GSSAPIAuthentication directive in ~/.ssh/config is not required. The authentication method is always attempted when offered by the server. Change the order in which methods are tried with PreferredAuthentications instead. Methods not listed are still tried afterwards.

References#