Skip to content

Instantly share code, notes, and snippets.

@joshbetz
Last active December 10, 2015 19:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbetz/4480919 to your computer and use it in GitHub Desktop.
Save joshbetz/4480919 to your computer and use it in GitHub Desktop.
A version of ssh-copy-id for the .bashrc file on your Mac.
ssh-copy-id() {
USER=$(whoami)
USAGE="Usage: `basename $0` [-i FILE] user@host"
FILE="$HOME/.ssh/id_rsa.pub"
if [ $# -lt 1 ]; then
echo "$USAGE"
fi
while getopts “i::” OPTION; do
case $OPTION in
i)
FILE=$OPTARG
;;
?)
echo "$USAGE"
;;
esac
done
shift $OPTIND-1
cat $FILE | ssh $1 "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"
}
@vjanelle
Copy link

vjanelle commented Jan 8, 2013

Might want to use $HOME instead of /Users/$USER, that'll be more portable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment