Skip to content

Instantly share code, notes, and snippets.

@egroeper
Created April 24, 2015 21:22
Show Gist options
  • Save egroeper/2d604c53408bfe1172a9 to your computer and use it in GitHub Desktop.
Save egroeper/2d604c53408bfe1172a9 to your computer and use it in GitHub Desktop.
ssh-copy-pubkey BASH function for .bashrc
# ssh-copy-pubkey <keyfile.pub> [user@]host
# this one avoids duplicates (stupid version by using fgrep, should only check pubkey part, not comments)
ssh-copy-pubkey() {
export PUBKEYTOCOPY=$(cat $1); ssh $2 "mkdir -p .ssh ; touch .ssh/authorized_keys ; if ! fgrep -q \"$PUBKEYTOCOPY\" .ssh/authorized_keys ; then echo $PUBKEYTOCOPY >> .ssh/authorized_keys; fi"; unset PUBKEYTOCOPY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment