After CERN IT required 2FA for SSH access for everyone, I was on the beta testing since the end of 2024. I was relying on a setup (blog post about it) that depended on the SSH agent of 1password plus the 1password CLI. This worked well, but I wanted a more native solution that would integrate seamlessly with my SSH config and not require the 1password CLI.
CERN supports Kerberos for SSH authentication, so I decided to set it up on my macOS machine. Here is how I did it.
macOS comes with the Heimdal Kerberos client by default, typically including the commands kinit, klist, and kdestroy. To check if the Kerberos client binaries are present, run this command in the terminal:
You should see output similar to this:
Kerberos tools are included in the base macOS system, so you usually do not need to install anything extra. However, if you have customized your system or removed developer tools, you may need to reinstall the Xcode Command Line Tools, which can be installed with:
Note that Kerberos client binaries are part of the base system rather than the Xcode tools themselves.
Configure Kerberos for CERN
We configure the Kerberos realm for CERN by creating or editing the configuration file krb5.conf. On macOS, the system-wide file is at /etc/krb5.conf. Some users may also have user-specific configs at ~/Library/Preferences/krb5.conf which override system settings.
Create or open the system config with:
Add the following content:
This configuration tells your Kerberos client to use CERN's KDC and realm for authentication, leveraging DNS to locate the proper servers.
Obtain and Manage Kerberos Tickets
Now test the configuration by obtaining a Kerberos ticket:
Replace <your_cern_username> with your CERN username. You will be prompted for your CERN password and 2FA during this step.
Important: The realm CERN.CH must be in uppercase, or authentication will fail.
If successful, the ticket will be valid by default for 25 hours and renewable for up to 5 days. You can view your ticket details with:
Example output:
To renew an existing valid ticket within its renewable period, you can run:
To destroy the ticket (log out), run:
Configure SSH for Kerberos Authentication
Edit your SSH configuration file ~/.ssh/config and add the following lines:
Replace <your_cern_username> with your actual CERN account name.
This config enables SSH to use GSSAPI with Kerberos for authentication, allowing single sign-on using your Kerberos ticket. The delegation option allows forwarding credentials to remote hosts.
Testing SSH Login
Now you can test SSH login to a CERN host without entering your password every time:
This will succeed without a password prompt if you have a valid Kerberos ticket. If no valid ticket is found, it will prompt for your password and 2FA.
2FA is required only when obtaining your Kerberos ticket (kinit), so subsequent SSH authentications are seamless as long as your ticket remains valid.
I actually have more complex ~/.ssh/config file that I use for my SSH connections, but the above configuration is the minimum required to set up Kerberos for SSH authentication with CERN. It does have *.cern.ch as the host, so it will work for all CERN hosts. You can also add more specific configurations for other CERN hosts if needed. This is specially needed is you have lbgw (Linux Batch Gateway) host where you need to tunnel through lxplus to access it. But it is not needed for the basic setup.
Note on 2FA prompts and SSH session persistence
While 2FA is required only when obtaining your Kerberos ticket using kinit, in practice, you may/will still be prompted for 2FA at each new SSH login if you do not maintain an active SSH session or persistent connection.
This happens because Kerberos authentication by itself does not keep SSH sessions alive or cache authentication across multiple connection attempts like SSH multiplexing features do.
To avoid repeated 2FA prompts during multiple SSH connections, consider enabling SSH connection multiplexing by adding this to your SSH config:
With this setup, the first SSH connection to a host establishes a master session, and subsequent connections reuse it transparently, reducing the need to reauthenticate and enter 2FA again within the persistence window. Using Kerberos authentication together with SSH multiplexing combines secure ticket-based authentication and seamless session reuse, effectively replacing older password-based workflows with repeated 2FA.