From 9b60386710a01033526d671d58ba4bca49a7ef31 Mon Sep 17 00:00:00 2001 From: Marco Raber Date: Sat, 11 Jun 2022 16:23:55 +0200 Subject: [PATCH] added first pubkey automation for yubikey --- sshin | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sshin b/sshin index 5a1739c..9b1ae57 100755 --- a/sshin +++ b/sshin @@ -14,6 +14,12 @@ IP_PREFIX="192.168.1." [[ $# -le 1 ]] && usage && exit 1 [[ $1 = "-h" ]] && usage -h && exit 1 re='^[0-9]+$' + +USUAL_PUBKEY=~/.ssh/id_rsa +YUBIKEY_PUBKEY=~/.ssh/id_ed25519_sk + +HOSTS_FILE=~/.local/share/sshin/hosts + command="ssh ${1}@" shift if [[ $1 =~ $re ]] @@ -27,5 +33,17 @@ else dport=$(grep $1 $ports_file | awk '{print $NF}') [[ -n $port ]] && command="${command} -D$dport" fi + +#check if Yubikey is present +lsusb | grep -q "Yubico" && YUBIKEY_PRESENCE=1 || YUBIKEY_PRESENCE=0 + +#check if the host you are connecting to has Yubikey support (both client and server need openssh >= 8.2) +YUBIKEY_SUPPORT=$(cat $HOSTS_FILE | grep $1 | awk '{print $2}') +[[ $YUBIKEY_SUPPORT = "" ]] && echo "vuoto" && YUBIKEY_SUPPORT=0 + + +[[ $YUBIKEY_PRESENCE -eq 1 ]] && [[ $YUBIKEY_SUPPORT -eq 1 ]] && command="${command} -i $YUBIKEY_PUBKEY" || command="${command} -i $USUAL_PUBKEY" + echo $command +#echo $YUBIKEY_SUPPORT $command