Last active
February 2, 2023 20:14
-
-
Save mutukrish/183409e84a51620394f16d4fc6225d96 to your computer and use it in GitHub Desktop.
Ssh autogenerate
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
_github_check_login () { | |
if ssh [email protected] 2> /dev/null; then | |
echo "Should never happen, ssh to git always fails with 'does not provide shell access'" | |
exit 1 | |
else | |
ssh_exit_status=$? | |
if [ $ssh_exit_status = 255 ]; then | |
return 1 | |
else | |
return 0 | |
fi | |
fi | |
} | |
_github_ssh_setup () { | |
defaultFileName="id_rsa" | |
read -p "Please enter your ssh key file name [id_rsa]: " sshFileName && [[ -z "$sshFileName" ]] && sshFileName="$defaultFileName" | |
echo "creating file a ssh key name $sshFileName" | |
echo "You'll be prompted to enter a passphrase for the new key" | |
ssh-keygen -b 4096 -f ~/.ssh/$sshFileName -t rsa | |
echo "" | |
echo "Now you need to add the new key to your GitHub account" | |
echo "Key copied to clipboard:" | |
echo "" | |
pbcopy < ~/.ssh/$sshFileName.pub | |
echo "" | |
echo "Then, go to (or Cmd+doubleclick) https://github.com/settings/ssh/new, paste, and press the green button" | |
echo "" | |
echo "This script will wait for the key to be added" | |
echo "Press Ctrl+C if you can't get into your GitHub account to add it right now. You'll be able to re-run it later to pick up where you left off." | |
sleep 20 # a long sleep at the beginning appears to make it easier to go to url in terminal | |
while ! _github_check_login; do | |
echo -n . | |
sleep 5 | |
done | |
echo "\a" | |
echo "You logged into GitHub!" | |
} | |
ssh_setup () { | |
_github_ssh_setup | |
} | |
ssh_setup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment