Skip to content

Instantly share code, notes, and snippets.

@pysysops
Last active August 18, 2016 09:14
Show Gist options
  • Select an option

  • Save pysysops/ea47b583ace803679e86 to your computer and use it in GitHub Desktop.

Select an option

Save pysysops/ea47b583ace803679e86 to your computer and use it in GitHub Desktop.
Add an SSH Key and push it to your Github Enterprise account using the API. Great for lazy people like me!
#!/bin/sh
GIT_SERVER="git.example.com"
GITHUB_API_URL="https://$GIT_SERVER/api/v3"
# Setup an SSH key
if [ ! -f ~/.ssh/id_rsa ]; then
ssh-keygen -b 4096 -t rsa -f ~/.ssh/id_rsa -q -N ""
fi
read -p "Enter your $GIT_SERVER username: " GIT_USERNAME
read -s -p "Enter your password for $GIT_USERNAME: " GIT_PASSWORD
curl -s -u "$GIT_USERNAME:$GIT_PASSWORD" \
--data "{\"title\":\"`whoami`_`date +%Y%m%d%H%M%S`\",\"key\":\"`cat ~/.ssh/id_rsa.pub`\"}" \
$GITHUB_API_URL/user/keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment