3

I'm storing my ssh keys on a yubikey and hence I don't have any private key file on disk. This gives me a problem when I'm also using OpenSSH Certificates to authenticate. If I would like to bring the certificate with me using the ssh-agent I need to add it to the agent some how.

This is done automatically if I have a private key called priv and a cert called priv-cert.pub. But since I don't have a file I cant find a way to add the certificate file to the agent.

Does anyone have a clue how to do this?

It seems there is no support for this, I found this feature request: https://bugzilla.mindrot.org/show_bug.cgi?id=2472

0

2 Answers 2

0

Yubikey documentation mentions that you can add certificates to the ssh-agent here https://developers.yubico.com/PIV/Guides/SSH_user_certificates.html

1
  • No it does not. You can add pkcs11 providers but you cannot add certificate files without a corresponding key file on disk. There is a ticket in OpenSSH Bugzilla about it. bugzilla.mindrot.org/show_bug.cgi?id=2472
    – Peter
    Commented Jun 5, 2018 at 14:26
0

ssh with Certificates and Hardware Token

This Q might be quite old but hardware auth is getting more common nowadays. The following should work with different hardware keys, as long as the private key is provided by an ssh-agent or a substitute like gpg-agent.

TL;DR

Just provide your public key file in the -i parameter of the ssh command:

ssh -o CertificateFile=yubikey-cert.pub -i yubikey.pub [email protected]

Step by step

This guide has been tested with ssh version:

OpenSSH_7.9p1 Raspbian-10+deb10u2+rpt1, OpenSSL 1.1.1n  15 Mar 2022

It is assumed that the private key has been created on the hardware token. There's absolutely no way to retrieve the private key from the token and store it in a file. The key is accessible only by a software driver that emulates an ssh-agent and provides the usual SSH_AUTH_SOCK environment variable. For using the key this driver communicates with the hardware token and any use of the key happens on the token's microcontroller.

Get the Public Key

The public key of the token's private key is needed. The key's hash can be seen by:

ssh-add -l

Output:

4096 SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx cardno:000000000000 (RSA)

The public key can be retrieved and stored in a file:

ssh-add -L > yubikey.pub

Output:

cat yubikey.pub
ssh-rsa AAA.........XXX== cardno:000000000000 

Sign the Public Key

Now the public key can be signed with the Certificate Authorities private key, to create a certificate:

ssh-keygen -s ca.key -I "keyID" -n user -z 4711 yubikey.pub

This generates the certificate file yubikey-cert.pub. Of course the proper keyID and serial (-z parameter) should be provided.

Use the Certificate

The certificate can now be used directly in the ssh command. Without relying on the implicit mechanism, key and cert can be passed to ssh on the command line. The private key must of course be available in the ssh-agent.

ssh -o CertificateFile=yubikey-cert.pub -i yubikey.pub [email protected]

For troubleshooting the -v switch of ssh can be used to get more details about which key and cert is used:

ssh -v -o CertificateFile=yubikey-cert.pub -i yubikey.pub [email protected]

Output (truncated for brevity):

...
debug1: Will attempt key: yubikey-cert.pub RSA-CERT SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx explicit
debug1: Will attempt key: yubikey.pub RSA SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx explicit agent
debug1: Will attempt key: ...
...
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: yubikey-cert.pub RSA-CERT SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx explicit
debug1: Server accepts key: yubikey-cert.pub RSA-CERT SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx explicit
debug1: Authentication succeeded (publickey).
...

A full tutorial of ssh certificates is out of scope of this answer. More information can be found e.g. at the OpenhSSH Cookbook.

1
  • This works for ssh but not when signing things with ssh-keygen -Y because it is not possible to supply the CertificateFile option with -O. ssh-agent simply answers with process_sign_request2: RSA-CERT key not found because ssh-add loaded the private key without a certificate.
    – andsens
    Commented Sep 11, 2023 at 10:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .