blob: 9ea225dda3d4d8b1c9c5dabaa3b3b53888ace724 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#!/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 <private-key-file> <server1> [server2 .. serverN]"
exit 1
elif [ ! -e "$KEY" ]; then
echo "$BASENAME: file not found: $KEY"
exit 1
elif [ ! -e "$KEY.pub" ]; then
echo "$BASENAME: file not found: $KEY.pub"
exit 1
fi
# 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"
# Private key
cat $KEY | ssh $SERVER "mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch $DESTKEY && chmod 600 $DESTKEY && cat >> $DESTKEY"
done
|