Created
September 4, 2018 00:11
-
-
Save gigafied/281a6fecc70966fa96ca257bac635303 to your computer and use it in GitHub Desktop.
GH RSA Script
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
#!/bin/bash | |
RSA_FILE_PATH="~/.ssh/github_rsa" | |
RSA_FILE="${RSA_FILE_PATH/#\~/$HOME}" | |
CONFIG_FILE=~/.ssh/config | |
read -p 'Github RSA Key Email: ' emailvar | |
read -sp 'Github RSA Key Password: ' passvar | |
mkdir -p ~/.ssh | |
ssh-keygen -t rsa -b 4096 -C "$emailvar" -N "$passvar" -f $RSA_FILE | |
eval "$(ssh-agent -s)" | |
/usr/bin/ssh-add -K $RSA_FILE | |
SSH_CONF=$(cat <<-END | |
Host github.com | |
IgnoreUnknown AddKeysToAgent,UseKeychain | |
AddKeysToAgent yes | |
UseKeychain yes | |
IdentityFile $RSA_FILE_PATH | |
END | |
) | |
if [ -f $CONFIG_FILE ]; then | |
grep "$RSA_FILE_PATH" $CONFIG_FILE || { | |
cat <<< "$SSH_CONF" >> $CONFIG_FILE | |
} | |
else | |
cat <<< "$SSH_CONF" > $CONFIG_FILE | |
fi | |
pbcopy < ${RSA_FILE}.pub | |
open 'https://github.com/settings/ssh/new' | |
echo 'Github RSA public key copied to clipboard' | |
read -p "After you've added your key, you can test by hitting enter." blah | |
ssh -T [email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment