From 865f31757cee0de1d38f7831509dc745c9021492 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 14 Mar 2017 10:43:44 -0300 Subject: Support for multiple servers on ssh-privsend and ssh-authorized-send --- ssh-authorized-send | 15 ++++++++++----- ssh-privsend | 25 +++++++++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/ssh-authorized-send b/ssh-authorized-send index ac687ff..22f5596 100755 --- a/ssh-authorized-send +++ b/ssh-authorized-send @@ -6,12 +6,11 @@ # Parameters BASENAME="`basename $0`" KEY="$1" -SERVER="$2" -DESTKEY="~/.ssh/`basename $KEY`" +SERVERS="$*" # Checks -if [ -z "$KEY" ]; then - echo "usage: $BASENAME " +if [ -z "$SERVERS" ]; then + echo "usage: $BASENAME [server2 .. serverN]" exit 1 elif [ ! -e "$KEY" ]; then echo "$BASENAME: file not found: $KEY" @@ -21,5 +20,11 @@ elif grep -q -i private $KEY; then exit 1 fi +# Destination key +DESTKEY="~/.ssh/`basename $KEY`" + # Put on authorized_keys -cat $KEY | ssh $SERVER "mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && cat >> ~/.ssh/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 diff --git a/ssh-privsend b/ssh-privsend index 3770898..55f4bfb 100755 --- a/ssh-privsend +++ b/ssh-privsend @@ -6,12 +6,11 @@ # Parameters BASENAME="`basename $0`" KEY="$1" -SERVER="$2" -DESTKEY="~/.ssh/`basename $KEY`" +SERVERS="$*" # Checks -if [ -z "$KEY" ]; then - echo "usage: $BASENAME " +if [ -z "$SERVERS" ]; then + echo "usage: $BASENAME [server2 .. serverN]" exit 1 elif [ ! -e "$KEY" ]; then echo "$BASENAME: file not found: $KEY" @@ -21,11 +20,17 @@ elif [ ! -e "$KEY.pub" ]; then exit 1 fi -# Put on authorized_keys -#ssh-authorized-send $KEY.pub +# Destination key +DESTKEY="~/.ssh/`basename $KEY`" + +for SERVER in $SERVERS; do + echo "Uploading keypair $SERVER..." + # Put on authorized_keys + #ssh-authorized-send $KEY.pub $SERVER -# Public key -cat $KEY.pub | ssh $SERVER "mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch $DESTKEY.pub && chmod 600 $DESTKEY.pub && cat >> $DESTKEY.pub" + # Public key + cat $KEY.pub | ssh $SERVER "mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch $DESTKEY.pub && chmod 600 $DESTKEY.pub && cat >> $DESTKEY.pub" -# Private key -cat $KEY | ssh $SERVER "mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch $DESTKEY && chmod 600 $DESTKEY && cat >> $DESTKEY" + # Private key + cat $KEY | ssh $SERVER "mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch $DESTKEY && chmod 600 $DESTKEY && cat >> $DESTKEY" +done -- cgit v1.2.3