Skip to content

Instantly share code, notes, and snippets.

@gigafied
Created September 4, 2018 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gigafied/281a6fecc70966fa96ca257bac635303 to your computer and use it in GitHub Desktop.
Save gigafied/281a6fecc70966fa96ca257bac635303 to your computer and use it in GitHub Desktop.
GH RSA Script
#!/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 git@github.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment