SSH Keys in the Mac Secure Enclave: A Native Setup and Its Trade-offs


A private SSH key stored in ~/.ssh is a file. File permissions help, and a passphrase adds a useful barrier, but a program running as you may still copy the encrypted key and attempt to use or attack it later. A hardware-backed key changes that part of the threat model: the private key stays on the device, while SSH asks the device to sign a challenge.

On recent macOS versions, Apple’s Secure Enclave can do this through CryptoTokenKit and the built-in OpenSSH security-key interface. The setup uses macOS tools, although the user experience still feels like a low-level integration. Here is the complete path, including the details that tend to derail a first attempt.

What changes when the key lives in hardware

Ordinary public-key authentication never sends a private key to the server. The client proves possession by signing data associated with the connection; the server checks the signature against a public key in authorized_keys. A Secure Enclave key keeps this server-side model. What changes is where signing happens.

The Secure Enclave creates and retains a nonexportable P-256 private key. A small resident-key handle on disk lets OpenSSH find it through Apple’s provider. That handle is useful only with the device that owns the key. The public key remains safe to copy to servers. Requiring biometrics adds an approval step each time the key is used.

SSH asks the local provider to sign a challenge with a Secure Enclave key after biometric approval; the server receives a signature, never the private key.
Only the public key and signatures cross the network.

This is stronger protection against key-file theft. It is not a guarantee that a compromised Mac cannot authenticate: malware operating in an active session might ask the signing interface to use the key. A biometric requirement makes those uses visible and harder to trigger silently, but it does not clean a compromised system.

Create the identity

First, confirm the Mac supports the feature and has Touch ID enrolled. Then create a CryptoTokenKit identity:

sc_auth create-ctk-identity -l "ssh-MacBook" -k p-256-ne -t bio
sc_auth list-ctk-identities

The label is local. p-256-ne requests a nonexportable P-256 key, and bio requires biometric approval. The list command lets you verify that an identity exists and shows its protection setting. If creation fails with a biometric authentication error, check Touch ID enrollment in System Settings; re-enrolling fixed that failure in Serge Gatezh’s documented experiment.

Do not expect a conventional id_ed25519 private-key file. OpenSSH must use Apple’s security-key provider to discover the resident identity and make a local handle:

cd ~/.ssh
ssh-keygen -w /usr/lib/ssh-keychain.dylib -K -N ""

OpenSSH’s -K downloads resident-key references from the selected provider, and -w chooses that provider. Accept the Touch ID prompt. If a PIN prompt appears for this biometric identity, press Enter. The command writes id_ecdsa_sk_rk and id_ecdsa_sk_rk.pub in the current directory. The first is a handle, despite its private-key-like filename; keep its permissions restricted and do not confuse it with an export of the enclave secret. Run the command in a separate empty directory first if you already have resident security keys and want to inspect every file before moving it into ~/.ssh.

Wire the handle into SSH

Point OpenSSH at the provider and explicitly select the handle. In a shell startup file such as ~/.zshrc:

export SSH_SK_PROVIDER=/usr/lib/ssh-keychain.dylib

Open a new shell or export the variable in the current one. Then add a narrow host rule to ~/.ssh/config:

Host my-server
    HostName server.example.com
    User alice
    IdentityFile ~/.ssh/id_ecdsa_sk_rk
    IdentitiesOnly yes

An explicit IdentityFile matters because id_ecdsa_sk_rk is not among SSH’s usual automatically tried filenames. A per-host rule also avoids changing authentication for every service before the new key works. If another SSH agent is configured through IdentityAgent, inspect that setting while debugging; it can change which identities are offered.

The .pub file contains an sk-ecdsa-sha2-nistp256@openssh.com public key. Put that whole line in the remote account’s ~/.ssh/authorized_keys, either with ssh-copy-id -i ~/.ssh/id_ecdsa_sk_rk.pub alice@server.example.com or by installing it through your server’s normal access process. The final space-separated field is only a comment. The FIDO application identifier is encoded inside the key data; changing the comment does not change the key.

Now test with verbose output:

ssh -vvv my-server

Look for the security-key identity being offered, approve Touch ID, and confirm the server accepts it. If SSH falls back to a password, check the environment variable, the handle path, the server’s public-key line, and any agent configuration. The --apple-use-keychain option is for storing conventional SSH key passphrases in Keychain; it is not this CryptoTokenKit provider path.

The cost of tying a key to one Mac

A nonexportable key cannot be restored onto a replacement computer. Treat device loss as an access-recovery problem before it happens. Register a second independent key, such as one on another Mac or a hardware security key, with every important service. Keep an administrative recovery route that does not depend on this laptop. When replacing the Mac, generate a fresh key and remove the old public key from servers and hosted accounts.

Two independent device keys are registered with a service; losing one device leaves the other as a recovery path, then the lost key is revoked and replaced.
Recovery requires another trusted credential before the first Mac is lost.

Biometric approval on every SSH operation is a deliberate friction point. It can become tedious for frequent Git operations or automation, where an unattended prompt may be impossible. Decide which accounts truly need interactive approval. Avoid removing -t bio merely because the prompt is unattractive: without it, software with access to the signing interface can potentially ask for signatures without a human tap.

The native prompt may show the cryptic name ctccardtoken. Gatezh ultimately preferred Secretive for a clearer interface. Secretive also uses Secure Enclave-backed keys and exposes an SSH agent, but it adds an app to maintain and configure. A separate FIDO2 hardware key is another option when portability between computers is more important than keeping the credential inside one Mac.

The useful takeaway is a precise one: Secure Enclave storage makes the private key nonexportable and preserves ordinary SSH public-key deployment. The practical setup still depends on a provider, a local handle, an explicit SSH identity, and a recovery key. Those operational pieces matter as much as the chip.

Sources

100%