Via ssh-copy-id Implementation for MinGW and MSYS
#!/bin/sh usage () { echo "Usage: $0 [-i [identity_file]] [user@]machine" exit 1 } # Parse options while getopts ":i:" o do case "$o" in i) # Identity file specified if [ $(($OPTIND-1)) -eq $# ] # if there's no other argument after this one then # Make sure last argument is not a file or folder to catch this case where no host is provided: # ssh-copy-id -i [identity_file] [ ! -f "$OPTARG" ] || usage [ ! -d "$OPTARG" ] || usage # If last argument is not a file, read the default key and continue key=`cat "$HOME/.ssh/id_rsa.pub"` # else # read specified identity [ -f "$OPTARG" ] || usage key=`cat "$OPTARG"` fi;; [?]) usage;; esac done [ $# -gt 0 ] || usage shift $(($# - 1)) # Show usage if no host given host=$1 if [ -z "$host" ] then usage fi # Default to `ssh-add -L` if no -i option given if [ -z "$key" ] then key=`ssh-add -L` fi echo "Uploading private key..." ssh $host 'mkdir -pm 700 ~/.ssh; echo ' $key ' >> ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys' echo "Done." exit 0