What are SSH keys in the Secure Enclave?
A normal SSH key is a file in ~/.ssh. Anything that can read that file, a stolen backup or a bad package in your shell, can copy the key and use it from anywhere. A key in the Secure Enclave is made inside the security chip of the device, and the private part never leaves it. Your computer asks the chip to sign; the chip answers, optionally after Touch ID or Face ID.
Four ways to get there, from the most built-in to the most portable:
| Option | Where the key lives | Key type | Devices |
|---|---|---|---|
macOS built-in (sc_auth) | Secure Enclave of the Mac | sk-ecdsa P-256 | Mac |
| Secure Enclave agent app | Secure Enclave of the Mac | ECDSA P-256 | Mac |
| SSH app with device keys | Secure Enclave of each device | ECDSA P-256 | Mac, iPhone, iPad |
| FIDO2 security key | The security key itself | ed25519-sk or ecdsa-sk | Any computer you plug it into |
The last row is not the Secure Enclave, but people search for it in the same breath, so it has its own section below.
Why keep SSH keys in the Secure Enclave?
- The key cannot be copied. Apple's documentation is plain about it: there is no way to move key data into or out of the Secure Enclave. Malware can ask for a signature while it runs on your Mac, but it cannot take the key away.
- Each use can need you. With biometrics on, every sign-in waits for Touch ID or Face ID, so a hidden process cannot sign quietly in the background.
- No passphrase to remember. The chip guards the key instead.
The trade-offs come from the same design. You cannot back the key up or carry it to a new Mac, so each device gets its own key. The chip only knows NIST P-256 curves, so the key is ECDSA, never Ed25519. And Apple lists the hardware: iPhones and iPads with an A7 chip or later, and Macs with Apple silicon or with the Touch Bar and Touch ID.
Can you make Secure Enclave SSH keys on macOS without extra apps?
Yes, on recent macOS. Since macOS Tahoe, the system library /usr/lib/ssh-keychain.dylib, long used for smart cards, also works as a security key provider for the ssh that ships with macOS. Apple documents the pieces in the sc_auth and ssh-keychain man pages, and developers mapped out the steps below.
- Create a key in the Secure Enclave that needs Touch ID (
-nemeans not exportable):sc_auth create-ctk-identity -l ssh -k p-256-ne -t bio - Check it is there, with its SSH fingerprint:
sc_auth list-ctk-identities -t ssh - Write a small handle file for ssh in
~/.ssh. It holds a reference, not the key. Press Enter at the PIN prompt, then touch the sensor:
This writescd ~/.ssh ssh-keygen -w /usr/lib/ssh-keychain.dylib -K -N ""id_ecdsa_sk_rkandid_ecdsa_sk_rk.pub. - Tell ssh where the provider is, in
~/.zprofile:export SSH_SK_PROVIDER=/usr/lib/ssh-keychain.dylib - Copy the public key to a server and connect:
ssh-copy-id -i ~/.ssh/id_ecdsa_sk_rk.pub deploy@203.0.113.10 ssh -i ~/.ssh/id_ecdsa_sk_rk deploy@203.0.113.10
To load it into the agent instead of naming the file, run ssh-add -K -S /usr/lib/ssh-keychain.dylib. Two things to know: these keys appear to servers as sk-ecdsa-sha2-nistp256@openssh.com, which needs OpenSSH 8.2 or later on the server, and they live on this Mac only.
Secure Enclave SSH agents with Touch ID
Before macOS had this built in, people used agent apps, and many still do. Secretive, an open-source Mac app, is the best known: it creates keys in the Secure Enclave, asks for Touch ID or an Apple Watch when one is used, and shows a notification each time a key signs.
brew install secretive
You then point SSH at its agent with an IdentityAgent line in ~/.ssh/config, as its setup screen explains. The keys are plain ecdsa-sha2-nistp256, so they work on any OpenSSH server, old ones included. The limit is the same as before: a Mac app, for keys on that Mac.
Is an ed25519-sk key in the Secure Enclave?
No. ed25519-sk and ecdsa-sk are the key types OpenSSH added in version 8.2 for FIDO2 security keys such as a YubiKey. The private key lives on the token you plug in and touch, which means it travels with you to any computer.
ssh-keygen -t ed25519-sk -O resident -O verify-required -C "yubikey"
-O resident keeps the key on the token, so ssh-keygen -K can load it on another computer. -O verify-required asks for the token's PIN as well as the touch.
On a Mac, the ssh that comes with the system stops with No FIDO SecurityKeyProvider specified for these keys. Install OpenSSH from Homebrew (brew install openssh), which brings FIDO2 support, and use that ssh-keygen. The whole setup is in FIDO2 SSH keys with a YubiKey. In Wardterm, Security keys makes the same kind of key on a YubiKey from the Keys screen of the Mac app, and its SSH agent lets Terminal and git use it too.
How do you use SSH keys in the Secure Enclave on iPhone and iPad?
iOS has no terminal and no sc_auth, so the SSH app has to make the key. In Wardterm this is a key on this device, and it works the same on Mac, iPhone and iPad:
- Open Keys. On iPhone choose +, on Mac New Key.
- Choose Key on This Device and give it a name, such as the name of the device.
- Leave Ask for Touch ID or Face ID each time it is used on, then choose Create Key.
- Open the key, choose Add to a server and pick the server. The app signs in with the current login and adds the public key to
~/.ssh/authorized_keys. - Choose Use to sign in. From now on each connection asks for your face or finger.
The public key is ecdsa-sha2-nistp256, the type every current OpenSSH server accepts. The key shows as This device only: it is not synced, and your other devices make their own.
Which servers accept Secure Enclave SSH keys?
Plain ECDSA P-256 keys, from agent apps or device keys, work on any OpenSSH server with default settings. The sk-ecdsa keys from the macOS built-in need OpenSSH 8.2 or later on the server, which every current Linux release has. To check a server:
sudo sshd -T | grep pubkeyacceptedalgorithms
Look for ecdsa-sha2-nistp256 or sk-ecdsa-sha2-nistp256@openssh.com in the list. GitHub and the other code hosts accept both.
Plan for a lost or replaced device
A key that cannot be copied also cannot be restored. Plan for that on day one:
- One key per device. A server's
authorized_keysholds many keys, one per line. Add the Mac, the iPhone and the iPad separately, with a comment that says which is which. - A second way in. Keep a security key or a normal key with a strong passphrase in a safe place, so a lost phone does not lock you out.
- Remove the old key. When a device is gone, delete its line from every server. In Wardterm, also remove the device from your account.
For the keys you do want on every device, see how to use SSH keys on several devices. With sync on, those keys travel in the encrypted vault, while device keys stay on the chip where they were made.
Questions
Can I store an SSH key in the Secure Enclave on a Mac?
Yes. The Secure Enclave makes the key itself and never lets the private part out. On recent macOS, sc_auth create-ctk-identity with /usr/lib/ssh-keychain.dylib does it without extra software; agent apps and SSH apps with device keys do it too.
Can I use Touch ID for SSH keys?
Yes, with a key in the Secure Enclave that is set to ask for biometrics. Each sign-in then waits for your finger on Touch ID, or your face on iPhone and iPad with Face ID.
Can the Secure Enclave hold an Ed25519 SSH key?
No. Apple's Secure Enclave works only with NIST P-256 elliptic curve keys, so the SSH key is ECDSA P-256. An ed25519-sk key lives on a FIDO2 security key such as a YubiKey, not in the Secure Enclave.
Can I back up a Secure Enclave SSH key?
No, and that is the point: the private key cannot leave the chip. Make one key per device, add each public key to your servers, and keep a second way in, such as a security key, in case a device is lost.
Does my server accept Secure Enclave keys?
Almost certainly. Plain ecdsa-sha2-nistp256 keys are accepted by OpenSSH servers by default. Keys of the sk-ecdsa type need OpenSSH 8.2 or later on the server. sudo sshd -T | grep pubkeyacceptedalgorithms shows the list.
Can I use an SSH key in the Secure Enclave on iPhone?
Yes, in an SSH app that creates device keys. In Wardterm, choose Key on This Device in Keys, add it to a server, and confirm each sign-in with Face ID or Touch ID.
Do Secure Enclave keys work with GitHub?
Yes. GitHub accepts ECDSA keys and the sk types used by security keys. Paste the public key in Settings, SSH and GPG keys, like any other key.
Sources
Each page was read on the date shown. Prices and features change, so check the maker's page before you decide.
- Protecting keys with the Secure Enclave, Apple Developer, read on
- sc_auth(8), macOS manual page, read on
- Native Secure Enclave SSH keys on macOS, gist by arianvp, read on
- Secretive, GitHub, read on
- OpenSSH 8.2 release notes (FIDO keys), read on
- Generating a new SSH key, GitHub Docs, read on
- Wardterm docs, keys on this device, read on
- Wardterm docs, security keys, read on