Created
March 8, 2023 13:40
-
-
Save noih/8cbfaa4a11932af6a417b68770a56f68 to your computer and use it in GitHub Desktop.
switch ssh key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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