-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsshConfig.sh
More file actions
64 lines (55 loc) · 1.3 KB
/
sshConfig.sh
File metadata and controls
64 lines (55 loc) · 1.3 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
inputfile=""
output=$HOME/.ssh/config
key_default="CTF.key"
# Options
while [ True ]; do
if [ "$1" = "--help" -o "$1" = "-h" ]; then
cat README.md
shift 1
elif [ "$1" = "--inputfile" -o "$1" = "-i" ]; then
inputfile=$2
shift 2
elif [ "$1" = "--key" -o "$1" = "-k" ]; then
key=$2
shift 2
elif [ -z $1 ]; then
break
else
echo "Unrecognized option: '$1'"
echo "See the output of '--help' or '-h' for a summary of options."
exit 1
fi
done
# Verify -i option
if [[ -z $inputfile ]]; then
echo "you must add the option: -i <inputfile>"
echo "inputfile form : <IP@>:<username>"
echo " <IP@>:<username>:<hostname>"
exit 1
fi
mkdir -p $HOME/.ssh
chmod 0700 $HOME/.ssh
# Gen ssh key
if [ -z "$key"]; then
key=$key_default
ssh-keygen -t rsa -b 4096 -f ~/.ssh/$key -C "CTF"
fi
# Create ssh config file
i=1
machineName_default="m"
while IFS=':' read -r hostName user machineName; do
if [ -z "$machineName"]; then
machineName=$machineName_default$i
fi
# Fill the ssh config file
echo "Host $machineName" >> $output
echo " HostName $hostName" >> $output
echo " User $user" >> $output
if [ "$key" -eq "$key_default"]; then
key=$key.pub
fi
ssh-copy-id -i $HOME/.ssh/$key $machineName
i=$((i+1))
done < "$inputfile"
cat $output