Skip to content

Commit ae37b11

Browse files
author
Gabriel Monroy
committed
add vagrant authorized-keys setup script
1 parent 5a1eb0b commit ae37b11

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
function echo_color {
4+
echo -e "\033[1m$1\033[0m"
5+
}
6+
7+
################
8+
# SSH settings #
9+
################
10+
ssh_key_path=~/.vagrant.d/insecure_private_key
11+
12+
# Create an SSH key pair for the deis user
13+
vagrant ssh -c "
14+
if [ ! -f ~/.ssh/id_rsa ]; then
15+
ssh-keygen -t rsa -N \"\" -f ~/.ssh/id_rsa
16+
chmod a+r ~/.ssh/id_rsa # Not strictly best practice, but the deis user needs to be able to read it
17+
fi"
18+
19+
# Copy the created key over to your local machine
20+
scp \
21+
-P22 \
22+
-o IdentityFile=$ssh_key_path \
23+
'vagrant@deis-controller.local:/home/vagrant/.ssh/id_rsa.pub' \
24+
'/tmp/vagrant_key'
25+
KEY=$(cat /tmp/vagrant_key)
26+
27+
if [ ! -n "$KEY" ]; then
28+
echo_color "Aborting. No SSH key copied from the Deis Controller"
29+
exit 1
30+
fi
31+
32+
if [ -z "$(grep "$KEY" ~/.ssh/authorized_keys )" ]; then
33+
echo $KEY >> ~/.ssh/authorized_keys;
34+
echo_color "Key added."
35+
else
36+
echo_color "Key already added."
37+
fi

0 commit comments

Comments
 (0)