A common application of security keys is as a hardware-backed SSH key. I have lately been curious as to whether it would be possible to use one as an SSH host key. It seems like it should be straightforward enough, it’s just another SSH key after all, if it works as a client identity key, why wouldn’t it work as a host key?

So I had a mess around with this, but haven’t been able to get it to work. Using sudo ssh-keygen -t ed25519-sk -O no-touch-required (or with -O resident as well) just ends up with the connection being refused and the auth log showing sshd: no hostkeys available -- exiting.

I had a look at the source for OpenSSH, but after 10 minutes of digging can find no indication of why it would cosider this to not be an ED25519_SK key, which the code explicitly accepts as a host key.

If anyone has any ideas for what is going wrong or has better luck, I would love to hear the details.

(Posted in selfhosted because this is the most prominent community that talks about ssh I can find, somewhat unsurprisingly)

EDIT to emphasize that this is talk about host keys like /etc/ssh/ssh_host_ed25519, not client keys. My attempts to make a working “ssh_host_ed25519_sk” are what I am reporting on here.

UPDATE: It works! So it ended up being a combination of a couple of confusing things, I believe.

One is that there is an old bug that means that ssh-keygen -K will accidentally make keys require user interaction again, which sshd then ignores as though they don’t exist. I believe this is what I was seeing previously, as I had been messing around with the keys elsewhere to verify them and then used ssh-keygen -K as a convenient way to drop them into /etc/ssh. But that alone would not have been enough to stop me, as I did try generating them in-place…

But I generated them with the name ssh_host_ed25519_sk_key, following the naming convention of id_ed25519_sk, and the fact that ED25519_SK is listed as a different enum value in the OpenSSH source. However, even upon stripping out every other key and enabling debug logging, it simply never even tried to touch that file as far as I could tell. So as an experiment I renamed it to ssh_host_ed25519_key as though it is a normal key, and that immediately worked exactly as expected!

So my final steps to get this working were:

sudo ssh-keygen -t ed25519_sk -O resident -O no-touch-required
Generating public/private ed25519-sk key pair.
You may need to touch your authenticator to authorize key generation.
Enter PIN for authenticator: 
Enter file in which to save the key (/root/.ssh/id_ed25519_sk): /etc/ssh/ssh_host_ed25519_key
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /etc/ssh/ssh_host_ed25519_key
Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub

Testing sshing into the host then works flawlessly as long as the security key is plugged in, and the connection is rejected the moment it is unplugged.

So this has been an interesting little experiment. Notably, because of the requirement for interaction with the security key, this will mess up anything else (like age) that uses the key directly as a cryptographic identity and isn’t smart enough to reach out to the security key.

Given how long it took me to find any information about this, hopefully this will serve someone well in future.

  • jetA
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    4 days ago

    Can you explain to me the workflow you have envisioned for the host identity key in /etc/ssh being keyed of a FIDO2 secure element? You plug a secure element into a server?

    Sounds like you want something like a HSM that integrates into your sshd to pull the certificates. Even then you have the chicken and egg problem, how do you identify the hardware to the HSM? You need some trusted boot environment, and now your down into vender specific implementations to “trust” the booted hardware.

    • gozz@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      4 days ago

      Yeah, the rough idea is to use any old FIDO2 key as a USB HSM. Not necessarily looking for a very practical solution (the easy fix would be to just encrypt the drive), but curious. What inspired this, though not necessarily the final application, is Nix secret distribution tools that use the host key as the secret recipient. This means that theoretically if you have the host identity tied to an external HSM or similar you could have the same image deploy as different machines based on what security key you have plugged in.

      • jetA
        link
        fedilink
        English
        arrow-up
        2
        ·
        4 days ago

        Fair enough;

        Do a dry run for a CLIENT key, make sure you have the libfido2 middleware installed and working; Ensure you have set your sshd_config file properly with no-touch-required

        From the documentation " Note: not all tokens support disabling the touch requirement." so do a test client side before banging your head on it.

        • gozz@lemmy.worldOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          4 days ago

          Got the client working (mostly) without issues again, though trying to imitate my process for host keys as closely as possible I did encounter some weirdness that led me to this open bug: https://bugzilla.mindrot.org/show_bug.cgi?id=3355 So that may be the source of my issues… If they keys I was using suddenly were secretly requiring touch, it would explain a lot. I can’t right now but I will do another experiment with host keys when I can. Still would love to see if anyone else is able to reproduce this behaviour or get it working.

        • gozz@lemmy.worldOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          4 days ago

          I previously have had no issues using this as a client key, but honestly I wouldn’t put it past myself to have picked the wrong key and not noticed. Maybe I will give it another try, but I don’t think that’s it.