aboutsummaryrefslogtreecommitdiff
path: root/ssh-privsend
blob: 3770898b6fe00ce9531404f586e59801b9599cf4 (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
#!/bin/bash
#
# Send both public and private keys to a server.
#

# Parameters
BASENAME="`basename $0`"
KEY="$1"
SERVER="$2"
DESTKEY="~/.ssh/`basename $KEY`"

# Checks
if [ -z "$KEY" ]; then
  echo "usage: $BASENAME <private-key-file>"
  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

# Put on authorized_keys
#ssh-authorized-send $KEY.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"