Skip to content

Instantly share code, notes, and snippets.

@dbannik
Created August 23, 2020 01:12
Show Gist options
  • Select an option

  • Save dbannik/330523f604c8ca9d275726545645b91c to your computer and use it in GitHub Desktop.

Select an option

Save dbannik/330523f604c8ca9d275726545645b91c to your computer and use it in GitHub Desktop.
Import github ssh user keys to user authorized
#!/usr/bin/env bash
username=$1
if [[ "$username" == "" ]];
then
echo "Please set 1 parameter"
echo "$0 username"
exit 1
fi
curl https://github.com/$username.keys -f || exit 1
mkdir -pm 700 ~/.ssh/ &&
touch ~/.ssh/authorized_keys &&
chmod 600 ~/.ssh/authorized_keys &&
cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys-bak &&
(cat ~/.ssh/authorized_keys-bak | awk '{print $1 " " $2}'; curl -s https://github.com/$username.keys) | sort | uniq > ~/.ssh/authorized_keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment