Skip to content

Instantly share code, notes, and snippets.

@diginfo
Last active June 17, 2020 10:12
Show Gist options
  • Save diginfo/68261e9709eb05046d473f9fc646389f to your computer and use it in GitHub Desktop.
Save diginfo/68261e9709eb05046d473f9fc646389f to your computer and use it in GitHub Desktop.
#!/bin/bash
## bash <(curl -Ls https://gist.github.com/diginfo/68261e9709eb05046d473f9fc646389f/raw/)
###
if [ "$#" -lt 2 ]; then
echo "keyadd repo path/to/rsa/file"
exit 1;
fi
REPO=$1;
PUBKEY=$2;
CONFIG="/etc/ssh/ssh_config"
HEAD="## github - $REPO ##";
#if ! grep -Fxq "$HEAD" $CONFIG; then
echo "adding config..."
cat <<EOF >>$CONFIG
$HEAD
Host $REPO.github.com
Hostname github.com
IdentityFile $PUBKEY
User diginfo
EOF
#fi
chmod 400 $PUBKEY;
## Add github.com to known hosts
ssh-keyscan github.com >> ~/.ssh/known_hosts
cat $CONFIG;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment