Last active
December 1, 2016 09:01
-
-
Save don-smith/6d3a9c706c7aa7af3b65d442401b962f to your computer and use it in GitHub Desktop.
Allows multiple GitHub users to use the same computers using individual SSH keys
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/sh | |
# This script creates an SSH key for use on GitHub | |
# Step 1: Copy and paste this github() function into the ~/.zshrc file | |
github() { | |
eval "$(ssh-agent -s)" | |
ssh-add ~/.ssh/$1 | |
email=`cat ~/.ssh/$1.email` | |
git config --global user.name $1 | |
git config --global user.email $email | |
} | |
# Step 2: Source .zshrc by running this in the terminal: | |
# source ~/.zshrc | |
# Step 3: Run this script passing the the GitHub username and | |
# email address associated with the GitHub account (see usage) | |
# Step 4: Apply credentials locally by running this in the terminal: | |
# github github-username | |
usage() { | |
echo "" | |
echo "This script creates an SSH key for use on GitHub." | |
echo "" | |
echo "./github.sh github-username github-email" | |
echo "" | |
} | |
createkey() { | |
echo $2 >> ~/.ssh/$1.email | |
ssh-keygen -t rsa -b 4096 -f ~/.ssh/$1 -C $2 | |
cp ~/.ssh/$1 . | |
cp ~/.ssh/$1.pub . | |
cp ~/.ssh/$1.email . | |
pbcopy < ./$1.pub | |
echo "Your public key has been copied to your clipboard." | |
echo "Go to https://github.com/settings/keys and create a new SSH key." | |
echo "Name the key 'EDA' and use the contents of your clipboard." | |
} | |
if [ "$#" -lt 2 ]; then | |
usage | |
else | |
createkey $1 $2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script copies the public and private key files (including the
username.email
file) to the current folder. So if you run this script from a thumb drive, it's easier to collect all the keys in one place to easily transfer them to the.ssh
folders on all shared computers.