-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcopysshkey.sh
executable file
·35 lines (27 loc) · 1.1 KB
/
copysshkey.sh
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
#!/bin/bash
# ----
# Copy a specifed SSH key into the ~/.ssh folder of the docker or virtualbox
# ----
if [[ $1 == '' || $2 == '' ]]; then
echo "Usage: ./copysshfile.sh (docker|virtualbox) <keyfile>";
else
destination=$1;
keyfile=$2;
tempfile=.sshconfiginfo.tmp
# Run the ssh-config command only once and save to temp file, to speed up things
vagrant ssh-config $destination > $tempfile;
echo "--------------------------------------------------------------------------------";
localkey=$(cat $tempfile | grep IdentityFile | awk '{ print $2 }');
hostname=$(cat $tempfile | grep HostName | awk '{ print $2 }');
port=$(cat $tempfile | grep Port | awk '{ print $2 }');
echo "Destination: "$destination;
echo "HostName: "$hostname;
echo "Port: "$port;
echo "Key to copy: "$keyfile;
echo "Localkey: "$localkey;
echo "--------------------------------------------------------------------------------";
echo "Trying to copy now: $keyfile ...";
scp -i $localkey $keyfile vagrant@$hostname:~/.ssh/
echo "--------------------------------------------------------------------------------";
rm $tempfile;
fi;