We have showed how to use SSH certificates and SSH CAs, we have also showed how you can use the yubikey to store you SSH keys. This article will describe how to combine these two features.
First of all you need to have a yubikey set up with some RSA/ECDSA keys. Then find out the public part of you key:
% ssh-keygen -D /usr/local/lib/opensc-pkcs11.so ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCHn4jSqvNLn5NtUxqlAlm1Qj1tlunb0PjBsItmmesquULAM5oqVYmwJ+bmXpDlzgeeIbl1lf3aUTsXCs6My8mkIUwwN+3a5AJ8MA18Bzzx/qIpxe2N/nZ61e03ua5B6SjpfxAAC6i3DPHU6kUSy26sXhfx14y6abWlrwhXaILsTogz2sOganS44au+nSpa35xwMxG5vehkRkYe6vQvvIDFeMhy61DAJGOcGeCbXTfJB9yYwAgOEqTvHDBfbTrHhmnUu82/JV6twY4/tdgrjFxGE3/JsRnoP3lBCoLQR+Uxs3mV7pFelQj/8bZKVsjdzqH9AYWpvIQTJGuwAmyOk61V
This public key should be handed over to your systems administratior (probably yourself in this case) for signing. In return you will get a OpenSSH certificate file that looks sort of a public key but a bit longer.
Now the “tricky” part comes. When you have your public key in ~/.ssh/id_rsa.pub ssh will automatically look for a certificate file called id_rsa-cert.pub. But since we are going to use the smartcard/yubikey to handle our key it will not be visible in ~/.ssh.
First give your certificate a reasonable name like ~/.ssh/yubikey-cert.pub. Then we could tell ssh to combine the two.
Me most basic way is then to just specify the options you need on the command line:
% ssh -o PKCS11Provider=/usr/local/lib/opensc-pkcs11.so -o CertificateFile=~/.ssh/yubikey-cert.pub peter@torus Enter PIN for 'PIV_II (PIV Card Holder pin)': [torus:~] peter>
If you want to use this permanently you can of course put the options in ~/.ssh/config instead it should look something like this:
A third option if you are using the ssh-agent (like me) you could first add the card to your agent:
% ssh-add -s /usr/local/lib/pkcs11/opensc-pkcs11.so Enter passphrase for PKCS#11: Card added: /usr/local/lib/pkcs11/opensc-pkcs11.so
and the specify the cert-file either on the command line or in ~/.ssh/config
% ssh -o CertificateFile=~/.ssh/yubikey-cert.pub peter@torus [torus:~] peter>
Now you should be able to combine ssh certificates and yubikeys/smart cards