A better ssh-copy-id | smithii.com

I wanted to authorize my web host with my Cygwin shell to do some backups. I’m used to ssh-copy-id but Cygwin doesn’t have it. I found this script that does the trick.

A better ssh-copy-id | smithii.com

I put this code in a ssh-copy-id.sh file.

#!/bin/sh
# $Id$

SSH="${HOME}/.ssh"

if [ ! -f "${SSH}/identity.pub" ]
then
PASSPHRASE=
read -p "Enter ssh passphrase for ${HOSTNAME}:" PASSPHRASE
ssh-keygen -t rsa1 -N "$PASSPHRASE" -f "${SSH}/identity"
ssh-keygen -t rsa -N "$PASSPHRASE" -f "${SSH}/id_rsa"
ssh-keygen -t dsa -N "$PASSPHRASE" -f "${SSH}/id_dsa"
chmod -f go-w "${SSH}" "${SSH}/authorized_keys*"
fi

cd "${SSH}" && \
tar -c id*.pub | \
ssh $* 'tar -x
SSH="${HOME}/.ssh"
if [ ! -f "${SSH}/identity.pub" ]
then
PASSPHRASE=
read -p "Enter ssh passphrase for ${HOSTNAME}:" PASSPHRASE
ssh-keygen -t rsa1 -N "$PASSPHRASE" -f "${SSH}/identity"
ssh-keygen -t rsa -N "$PASSPHRASE" -f "${SSH}/id_rsa"
ssh-keygen -t dsa -N "$PASSPHRASE" -f "${SSH}/id_dsa"
fi
cat identity.pub >>"${SSH}/authorized_keys"
cat id_dsa.pub id_rsa.pub >>"${SSH}/authorized_keys2"
chmod -f go-w "${SSH}" "${SSH}/authorized_keys*"
rm -f identity.pub id_dsa.pub id_rsa.pub
'