Files
Helper-Scripts/yubikey-setup/gpg-switch-yubikey
T
hendrik-hog 0868ce16aa Add YubiKey new-machine setup script
Self-contained setup.sh that imports the bundled public key, binds the YubiKey
card stubs, enables SSH via the auth key, and configures git signing — so a
fresh machine is provisioned without hunting for the public key. Idempotent and
verified end to end.
2026-07-24 19:28:15 +02:00

13 lines
517 B
Bash
Executable File

#!/bin/bash
# Re-learn the currently inserted YubiKey for GPG
FINGERPRINT="4A227DDEFA7A37048609549863C6571F1095CC5C"
KEYGRIPS=$(gpg --with-keygrip --list-secret-keys "$FINGERPRINT" 2>/dev/null | grep Keygrip | awk '{print $3}')
for kg in $KEYGRIPS; do
rm -f ~/.gnupg/private-keys-v1.d/${kg}.key
done
gpgconf --kill gpg-agent
gpgconf --kill scdaemon
sleep 1
gpg --card-status > /dev/null 2>&1 && echo "Switched to $(gpg --card-status 2>/dev/null | grep 'Serial number' | awk '{print $NF}')" || echo "No card found"