Skip to content

Instantly share code, notes, and snippets.

@maclarensg
Last active November 5, 2021 15:15
Show Gist options
  • Save maclarensg/180e8ba20d52300866ae41287cdfef8b to your computer and use it in GitHub Desktop.
Save maclarensg/180e8ba20d52300866ae41287cdfef8b to your computer and use it in GitHub Desktop.
switch ssh keys snippet
# add this in ur bashrc script
switch_ssh(){
envs=()
for file in $(find ~/.ssh -name "id_rsa.pub.*" -printf "%f\n"); do
runtime=$( echo $file | awk -F '.' '{print $NF}' )
envs+=( $runtime )
done
i=0
for env in ${envs[@]}; do
echo "$i) $env"
let i=i+1
done
printf "Enter env: "
read selection
echo "Choose ${envs[$selection]}."
rm ~/.ssh/id_rsa
rm ~/.ssh/id_rsa.pub
ln -s ~/.ssh/id_rsa.pub.${envs[$selection]} ~/.ssh/id_rsa.pub
ln -s ~/.ssh/id_rsa.${envs[$selection]} ~/.ssh/id_rsa
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment