Skip to content

Instantly share code, notes, and snippets.

@rutan
Last active January 3, 2016 14:39
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 rutan/8477626 to your computer and use it in GitHub Desktop.
Save rutan/8477626 to your computer and use it in GitHub Desktop.
#!/bin/bash
# GitHubの公開鍵をSSH認証用の鍵として登録する子
AUTHORIZED_KEYS_FILE="$HOME/.ssh/authorized_keys"
if [ -z $GITHUB_ACCOUNT ]; then
GITHUB_ACCOUNT='rutan'
fi
# 認証鍵の登録
ssh_pub_key=`curl https://github.com/"${GITHUB_ACCOUNT}".keys`
if [ ${#ssh_pub_key} -eq 1 ]; then
echo '鍵 is 見つからない'
exit 1;
fi
grep_result=`grep "${ssh_pub_key}" "${AUTHORIZED_KEYS_FILE}"`
if [ "$ssh_pub_key" = "$grep_result" ]; then
echo 'already registered ssh public key'
else
echo 'register ssh public key'
echo "${ssh_pub_key}" >> "$AUTHORIZED_KEYS_FILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment