-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh_push_config
executable file
·38 lines (30 loc) · 915 Bytes
/
ssh_push_config
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
#! /bin/bash
# vim: sw=4 sts=4 et si
#
# Push my ssh client configuration to a target machine
#
if [ $# -lt 2 ]; then
echo "USAGE: ssh_push_config <user> <hostname> <key>"
echo " <user> is the target user"
echo " <hostname> is the target host"
echo " <key> is optional. This will filter authorized keys by those that match the grep string <key>"
exit 1
fi
umask 077
cd $HOME/.ssh
if [ $? -gt 0 ]; then
"cd $HOME/.ssh failed"
exit 1
fi
user="$1"
host="$2"
authorized_cmd="grep ${3:-"-e ."}"
echo "Using authorized keys which match $authorized_cmd"
target="$user@$host"
${authorized_cmd} authorized_keys | ssh $target "mkdir .ssh; chmod 700 .ssh; tee -a .ssh/authorized_keys; chmod 600 .ssh/authorized_keys"
scp target-config $target:.ssh/config
cd $HOME
scp .bash_profile .root_bashrc $target:
ssh $target mkdir -p bin
scp bin/r $target:bin
scp bin/ssh_push_config $target:bin