Skip to content

Instantly share code, notes, and snippets.

@enihsyou
Last active July 22, 2020 08:20
Show Gist options
  • Save enihsyou/b2ef59c2d123b2e0f417fd924feadb4e to your computer and use it in GitHub Desktop.
Save enihsyou/b2ef59c2d123b2e0f417fd924feadb4e to your computer and use it in GitHub Desktop.
ssh-copy-id-gh
USERNAME=enihsyou
mkdir -p ~/.ssh
if ! [[ -f ~/.ssh/authorized_keys ]]; then
echo "Creating new ~/.ssh/authorized_keys"
touch ~/.ssh/authorized_keys
fi
keys=`curl https://api.github.com/users/$USERNAME/keys | grep -o -E "ssh-\w+\s+[^\"]+"`
for key in $keys; do
echo $key
grep -q "$key" ~/.ssh/authorized_keys || echo "$key" >> ~/.ssh/authorized_keys
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment