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
kinitor with your account on the Mac. The ticket is presented to the server using the SSH authentication methodgssapi-with-mic, the equivalent ofssh -o GSSAPIAuthentication=yes.
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 yesinsshd_configand has a keytab with the service principalhost/server.example.com@EXAMPLE.COMfor its fully qualified hostname. Refer to your administrator.Your principal such as
user@EXAMPLE.COMis allowed to log in to the account on the server. By default the principaluser@EXAMPLE.COMmaps to the accountuser. Additional principals are listed in~/.k5loginof 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#
Obtain a ticket for your principal. Enter the password of your Kerberos account when prompted.
kinit user@EXAMPLE.COMTip
Tickets obtained with Ticket Viewer.app in
/System/Library/CoreServices/Applicationsor when logging in to a Mac bound to a directory service with Kerberos are used as well.Verify a ticket for the realm is listed and has not expired.
klistVerify 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.comA service ticket for
host/server.example.com@EXAMPLE.COMis now listed withklist.Add a new Bookmark in Cyberduck or Mountain Duck. Enter the fully qualified hostname
server.example.comin 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.
Optionally enter the realm such as
EXAMPLE.COMin Kerberos Realm in the More Options tab of the bookmark when the server belongs to a different realm than your ticket.Connect to the server. No prompt is displayed when the ticket is accepted.
The ticket of MIT Kerberos for Windows is kept in memory by its credentials cache server and cannot be read directly. When MIT Kerberos for Windows is installed, the ticket granting ticket is copied to a temporary credentials cache file for the login using the klist.exe and kcpytkt.exe tools of MIT Kerberos for Windows. The temporary file is deleted afterwards.
Install MIT Kerberos for Windows in the default location. The tools are only looked up in
MIT\Kerberos\binof the Program Files folders%ProgramW6432%,%ProgramFiles%and%ProgramFiles(x86)%.Obtain a ticket for your principal with MIT Kerberos Ticket Manager or from the command line. Enter the password of your Kerberos account when prompted.
"%ProgramFiles%\MIT\Kerberos\bin\kinit.exe" user@EXAMPLE.COMVerify a ticket for the realm is listed and has not expired.
"%ProgramFiles%\MIT\Kerberos\bin\klist.exe"Add a new Bookmark. Enter the fully qualified hostname
server.example.comin 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.
Optionally enter the realm such as
EXAMPLE.COMin Kerberos Realm when the server belongs to a different realm than your ticket. The configurationkrb5.iniof MIT Kerberos for Windows in%ProgramData%\MIT\Kerberos5is not read.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.
The realm set in Kerberos Realm of the bookmark. The field is found in the More Options tab on macOS.
The realm the hostname is mapped to in
[domain_realm]or else thedefault_realmof the Kerberos configuration.The realm of your ticket such as
EXAMPLE.COMfor the principaluser@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.Kerberosor/etc/krb5.confLinux:
/etc/krb5.confWindows:
krb5.iniin the Windows directory such asC:\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 |
|---|---|
|
Set to |
|
Path to a credentials cache file to read the ticket from instead of the default cache. Obtain a ticket written to the file with |
|
Realm of the server set with Kerberos Realm in the bookmark. Refer to Kerberos Realm per Bookmark. |
|
Windows only. Set to |
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#
Java Kerberos Requirements for the lookup of the configuration file.