Last active
August 18, 2016 09:14
-
-
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!
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 | |
| 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