SSH keys in the Mac's Secure Enclave without third-party tools

I wanted an SSH key that can’t be copied off my Mac and that nothing can use without Touch ID, so a process running as me (a coding agent, say) can’t log in to a server on its own. macOS Tahoe can keep the private key in hardware, in the Secure Enclave, using only built-in tools. I followed arianvp’s gist.

# creates the key in the Secure Enclave
# -l ssh is its label, -k p-256-ne a non-exportable P-256 key, -t bio Touch ID on every use
sc_auth create-ctk-identity -l ssh -k p-256-ne -t bio
# -w loads macOS's library that presents the enclave as a hardware security key (like a YubiKey)
# -K writes a reference to the key into the current directory, named after the label (id_ecdsa_sk_rk_ssh)
# it asks for a security-key PIN, but there isn't one, so a blank Enter answers it
cd ~/.ssh && ssh-keygen -K -w /usr/lib/ssh-keychain.dylib -N ""
ssh-copy-id -i ~/.ssh/id_ecdsa_sk_rk_ssh.pub user@server.example.com

That file holds no secret, so it needs no passphrase. Servers see an sk-ecdsa-sha2-nistp256@openssh.com key, the same type a FIDO security key uses.

Before changing your SSH config, check the key works on that server. -F /dev/null ignores the config, so no other key can be the one that logs you in:

ssh -F /dev/null -o IdentitiesOnly=yes -o SecurityKeyProvider=/usr/lib/ssh-keychain.dylib -i ~/.ssh/id_ecdsa_sk_rk_ssh user@server.example.com true

Then point ~/.ssh/config at it:

Host *
  SecurityKeyProvider /usr/lib/ssh-keychain.dylib
  IdentityFile ~/.ssh/id_ecdsa_sk_rk_ssh
  # without it, ssh logs in with any key sitting in ssh-agent instead, with no Touch ID prompt
  IdentitiesOnly yes

As a personal preference, I also share one connection per host to cut down the prompts. With these lines under Host *, Touch ID asks once per host and not again until the connection has sat idle for four hours, but while it’s open any local process can use it without a prompt:

  ControlMaster auto
  ControlPath ~/.ssh/cm-%C
  ControlPersist 4h

Downsides

  • The key can’t be backed up or moved, so authorize a second key on each server, or a dead Mac leaves you adding a new one from the console. The gist also shows an exportable variant (-k p-256) if you want a backup.
  • Touch ID has to be reachable. With the lid closed, macOS reports Touch ID is not available in closed clamshell mode and doesn’t fall back to the Mac’s password (Alex Haydock hit this).
  • The enclave makes only P-256 keys, and a server that doesn’t support sk-ecdsa keys won’t take it. OpenWrt 25.12 (router firmware) builds its SSH server without ECDSA (Config.in), so it still needs an ordinary ed25519 key file.
  • The Touch ID prompt doesn’t mention SSH. It names an internal macOS process instead (Serge Gatezh’s post has a screenshot). I hope Apple fixes that, and if not I may move to Secretive, an app that keeps keys in the Secure Enclave and shows a clearer prompt.