Script to create SSH deploy keys to github
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
#!/bin/bash | |
# Install: | |
# wget https://gist.githubusercontent.com/eusonlito/39f15118cfa7a3fcab88cc80b4ef7ca8/raw/github-ssh.sh -O /usr/local/bin/github-ssh | |
# chmod 755 /usr/local/bin/github-ssh | |
# Usage: | |
# github-ssh "https://github.com/eusonlito/Password-Manager" | |
url="$1" | |
echo "" | |
if [ "$(echo $url | grep 'github.com')" == "" ]; then | |
echo "This script require a github.com repository URL" | |
exit 1 | |
fi | |
repository=$(echo "$url" | sed 's#https://github.com/##') | |
code=$(echo "$repository" | sed 's#/#-#') | |
read -p "Do you want to create a SSH key to $repository repository? [y/n] " yn | |
if [ "$yn" != "y" ]; then | |
echo "Bye!" | |
echo "" | |
exit 0 | |
fi | |
host="$code.github.com" | |
file=$HOME"/.ssh/id_rsa_$host" | |
if [ -f "$file" ]; then | |
echo "" | |
echo "File $file already exists" | |
exit 1 | |
fi | |
ssh-keygen -t rsa -b 4096 -f "$file" -q -N "" | |
cat <<EOF >> $HOME"/.ssh/config" | |
Host $host | |
Hostname github.com | |
IdentityFile=$file | |
EOF | |
echo "" | |
cat "$file.pub" | |
echo "" | |
echo "git remote add origin git@$host:$repository.git" | |
echo "" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment