Strovent SystemsSign in
Reference

Use an ed25519-sk security key with ssh-agent: ssh-add, providers and macOS

How ssh-add loads an ed25519-sk or ecdsa-sk key into ssh-agent, what SSH_SK_PROVIDER and ssh-agent -P change, and two OpenSSH installs on one Mac.

A security key file such as id_ed25519_sk is only a key handle: the private key stays inside the hardware key (see Security keys (FIDO2) with SSH). You can still load it into ssh-agent. The agent then asks the hardware key to sign each time a login needs it.

Load the key

ssh-add ~/.ssh/id_ed25519_sk
ssh-add -l

For a resident key that is stored on the security key itself, ssh-add -K loads the resident keys straight from the authenticator, with no file needed.

The security key still has to be plugged in, and touched, each time the agent signs. When the agent needs a touch, it can show "Confirm user presence for key …" through the SSH_ASKPASS program, but only if a display or SSH_ASKPASS_REQUIRE=force is set; otherwise there is no message, and you still have to touch the key.

Providers: how OpenSSH talks to the key

By default ssh, ssh-add and ssh-agent use OpenSSH's built-in USB HID support to reach the security key. If your OpenSSH needs a separate middleware library instead:

  • ssh-add -S /path/to/library uses that library when adding the key.
  • The environment variable SSH_SK_PROVIDER sets the library for any FIDO key ssh-add loads.
  • In ~/.ssh/config, SecurityKeyProvider does the same for ssh.

The agent only accepts provider libraries whose path matches its allow-list. ssh-agent -P sets that list; the default is /usr/lib/*,/usr/local/lib/*. A library elsewhere, for example under a package manager's own prefix, is refused until the agent is started with a -P pattern that matches it.

On a Mac: make sure all three tools are the same OpenSSH

A Mac can have the OpenSSH that comes with macOS and a second one from a package manager. They are separate programs with their own build options, so check that ssh, ssh-add and ssh-agent all come from the same one:

which ssh ssh-add ssh-agent
ssh -V
echo "$SSH_AUTH_SOCK"

SSH_AUTH_SOCK says which agent ssh-add and ssh talk to. Use the ssh-add and ssh from the same OpenSSH as that agent, or start that OpenSSH's own agent and point SSH_AUTH_SOCK at it.

Forwarded agents

By default only local clients of ssh-agent may load FIDO provider libraries. Clients of a forwarded agent cannot load PKCS#11 or FIDO provider libraries unless the agent was started with -O allow-remote-pkcs11. See SSH agent forwarding not working: Could not open a connection to your authentication agent.

Sources

Spotted a mistake? Email [email protected].