Protecting SSH Keys with macOS Secure Enclave

    Protecting SSH Keys with macOS Secure Enclave

    Secure Enclave on macOS provides a hardware‑backed key store that isolates private material from the rest of the system. When you generate an SSH key inside the enclave, the private key never leaves the secure coprocessor; only a public key is exported for the usual authorized_keys workflow. This means that even if malware gains root privileges, it cannot directly read the key material because the enclave enforces strict access controls and requires user authentication for each operation.

    To take advantage of this, you can use the built‑in `ssh-keygen -t ed25519-sk` option, which tells the system to create a security‑key‑backed Ed25519 key. macOS will automatically bind the key to the Secure Enclave and store a reference in the keychain. When you attempt an SSH connection, the SSH client asks the enclave to sign the challenge, prompting Touch ID or your password as a second factor. The signature is produced inside the enclave and returned to the client without ever exposing the raw private key.

    Integrating this workflow into your development environment is straightforward. Add the generated key to your `~/.ssh/config` with `IdentityFile ~/.ssh/id_ed25519_sk` and ensure `UseKeychain yes` is set so the system can retrieve the key reference automatically. If you use agents like `ssh-add -K`, macOS will load the reference into the background agent, still keeping the private component locked away. This gives you the convenience of agent forwarding while retaining the hardware protection.

    Because the key lives in Secure Enclave, backup strategies differ from traditional PEM files. You should export the public key for distribution, but the private key cannot be exported; instead, you rely on the device’s biometric or password authentication to unlock it. If you need to move the key to a new Mac, you must generate a new enclave‑backed key on that machine and update any servers that trusted the old public key. This trade‑off—stronger protection at the cost of portability—fits well for personal machines and CI runners that stay within the Apple ecosystem.

    Source: Protecting SSH Keys with macOS Secure Enclave

    Technology
    Coding
    0

    More on this topic