08.SSH FIDO2 - Jubijub/arch-config GitHub Wiki
The goal is to explain the generation and usage of SSH authentication / SSH signing using FIDO2 Yubikeys.
Note
|
historically I would follow the SSH+PGP keys stored on the Yubikey approach (cf DrDuh Yubikey Guide). But FIDO2 makes it much simpler, and since I don’t use GPG for anything else, it was too much hassle. |
paru -S yubikey-manager libfido2
sudo systemctl enable pcscd.service
sudo systemctl start pcscd.service
ykman info (1)
ykman fido access change-pin
-
Verify that FIDO2 is enabled.
Important
|
Each key has its own private/public key pair
|
ykman info (1)
ssh-keygen -t ed25519-sk -O resident -O verify-required -C “<key form factor + last 3 digit serial number>” (2)
-
note the last 3 digits of the serial number.
-
when prompted, directly specify the proper name :
~/.ssh/id_ed25519_sk-XXX
You can add the -O application=ssh:YourText
if you need more than one SSH
key per YubiKey.
Warning
|
don’t set any passphrase, press enter both times. |
ykman info (1)
mkdir ~/.ssh
cd ~/.ssh (2)
ssh-keygen -K
mv id_ed25519_sk_rk id_ed25519_sk-XXX (3)
mv id_ed25519_sk_rk.pub id_ed25519_sk-XXX.pub (3)
-
note the last 3 digits of the serial number.
-
important as the -K command downloads the key in the current directory.
-
where XXX are the last 3 digits of the serial number. Do note that the copied key will be called
*_sk_rk
, you need to remove that_rk
Important
|
see the explanation above, as git can only use one user.signingkey at a time, we will use a script to dynamically copy the right key into the ~/.ssh/id_ed25519_sk
|
Create the file /etc/udev/rules.d/99-yubikey-renaming.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="1050", ATTR{idProduct}=="0407", ACTION=="add", RUN+="/home/jubi/scripts/yubikey.sh"
#!/bin/bash
# detect-yubikey-and-set-signing-key.sh
#
#!/bin/bash
exec >> /tmp/yubikey.log 2>&1
export PATH="/usr/local/bin:/usr/bin:/bin"
export HOME="/home/jubi"
# Get YubiKey serial number
SERIAL_FULL=$(ykman info 2>/dev/null | grep "Serial number" | awk '{print $3}')
if [ -z "$SERIAL_FULL" ]; then
echo "$(date): No YubiKey detected or ykman failed"
exit 1
fi
# Get last 3 digits
SERIAL_LAST3=${SERIAL_FULL: -3}
echo "$(date): YubiKey serial: $SERIAL_FULL, last 3 digits: $SERIAL_LAST3"
SOURCE_KEY="$HOME/.ssh/id_ed25519_sk-$SERIAL_LAST3"
SOURCE_PUB="$HOME/.ssh/id_ed25519_sk-$SERIAL_LAST3.pub"
TARGET_KEY="$HOME/.ssh/id_ed25519_sk"
TARGET_PUB="$HOME/.ssh/id_ed25519_sk.pub"
if [ ! -f "$SOURCE_KEY" ]; then
echo "$(date): Source key not found: $SOURCE_KEY"
exit 1
fi
# Copy the keys
cp -f "$SOURCE_KEY" "$TARGET_KEY"
cp -f "$SOURCE_PUB" "$TARGET_PUB"
# Set proper permissions
chown jubi:users "$TARGET_KEY"
chown jubi:users "$TARGET_PUB"
chmod 600 "$TARGET_KEY"
chmod 644 "$TARGET_PUB"
echo "$TARGET_KEY and $TARGET_PUB successfully updated"
You can monitor the logs with tail -f /tmp/yubikey.log
.
git config --global gpg.format ssh (1)
git config --global user.signingkey ~/.ssh/id_ed25519_sk (2)
git config --global commit.gpgsign true
git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers
-
enables SSH key signing instead of GPG.
-
we will use
id_ed25519_sk
no matter what. The script will ensure that it contains the right key.
-
Login to Github
-
Click on top right profile icon > Settings
-
In
Password and authentication
, verify that the key has been added as a security key, and add it if not -
In
SSH and GPG keys
add the key twice:-
Add it as a SSH Authentication key
-
Add it as a SSH Signing key
-