Last active
November 5, 2021 15:15
-
-
Save maclarensg/180e8ba20d52300866ae41287cdfef8b to your computer and use it in GitHub Desktop.
switch ssh keys snippet
This file contains hidden or 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
# 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