#!/bin/bash # # Send both public and private keys to a server. # # Parameters BASENAME="`basename $0`" KEY="$1" # Servers shift SERVERS="$*" # Checks if [ -z "$SERVERS" ]; then echo "usage: $BASENAME [server2 .. serverN]" exit 1 elif [ ! -e "$KEY" ]; then echo "$BASENAME: file not found: $KEY" exit 1 elif grep -q -i private $KEY; then echo "$BASENAME: please do not send a private key!" exit 1 fi # Destination key DESTKEY="~/.ssh/`basename $KEY`" # Put on authorized_keys for SERVER in $SERVERS; do echo "Uploading key into $SERVER..." cat $KEY | ssh $SERVER "mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && cat >> ~/.ssh/authorized_keys" done