Skip to content

Instantly share code, notes, and snippets.

@noih
Created March 8, 2023 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noih/8cbfaa4a11932af6a417b68770a56f68 to your computer and use it in GitHub Desktop.
Save noih/8cbfaa4a11932af6a417b68770a56f68 to your computer and use it in GitHub Desktop.
switch ssh key
#!/bin/bash
# debug
#ssh -Tvvv git@gitlab.com
# clear
PS3="clear all ?"
select num in "clear" "no"
do
if [ "${num}" == "clear" ]; then
eval $(ssh-agent -s)
fi
break
done
hosts=("gitlab" "github")
# ssh key list
echo "keys:"
ssh-add -l
echo
# select file
PS3="Please choose your private key: "
select file in ~/.ssh/*
do
echo $file
# start ssh agent
# eval $(ssh-agent -s)
#echo
# ssh add
ssh-add $file
# select host
PS3="Please choose host: "
select h in "${hosts[@]}"
do
case $h in
"gitlab" | "github")
ssh -T "git@$h.com"
break
;;
*) echo "invalid option: $REPLY"
;;
esac
done
break
done
# ssh key list
echo "keys:"
ssh-add -l
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment