From bb6e4b9515a36dfc4be3e29aa77c8c8a6129f2ce Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Wed, 18 Jun 2014 05:22:53 +0200 Subject: [PATCH] Allow osbash to enable Vagrant ssh keys This script can be used to enable access to osbash VMs using the same ssh key that is used to for logging into Vagrant VMs. If the script is run from a directory shared with the host, the downloaded key will be cached. Partial-Bug: 1312764 Implements: blueprint openstack-training-labs Change-Id: Ia541e01cabd69f794ea79d8a318f490f518d28ef --- .../scripts/osbash/enable_vagrant_ssh_keys.sh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 labs/scripts/osbash/enable_vagrant_ssh_keys.sh diff --git a/labs/scripts/osbash/enable_vagrant_ssh_keys.sh b/labs/scripts/osbash/enable_vagrant_ssh_keys.sh new file mode 100644 index 00000000..e17cdbc3 --- /dev/null +++ b/labs/scripts/osbash/enable_vagrant_ssh_keys.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# This script installs the unsecure Vagrant ssh keys. This allows users to +# log into the VMs using these keys instead of a password. + +TOP_DIR=$(cd $(dirname "$0")/.. && pwd) +source "$TOP_DIR/config/paths" +source "$LIB_DIR/functions.guest" + +indicate_current_auto + +exec_logfile + +function install_vagrant_public_key { + local VAGRANT_KEY_NAME="vagrant.pub" + local KEY_URL=https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/$VAGRANT_KEY_NAME + local VAGRANT_KEY_DIR=$LIB_DIR/vagrant-ssh-keys + + if [ ! -f "$VAGRANT_KEY_DIR/$VAGRANT_KEY_NAME" ]; then + wget --output-document "$VAGRANT_KEY_DIR/$VAGRANT_KEY_NAME" "$KEY_URL" + if [ $? -ne 0 ]; then + echo >&2 "Error when downloading $KEY_URL" + return 1 + fi + fi + + mkdir -p "$HOME/.ssh" + chmod 700 "$HOME/.ssh" + cat "$VAGRANT_KEY_DIR/$VAGRANT_KEY_NAME" >> "$HOME/.ssh/authorized_keys" + chmod 400 "$HOME/.ssh/authorized_keys" +} + +if grep -qs "vagrant insecure public key" "$HOME/.ssh/authorized_keys"; then + echo "Vagrant insecure public key already installed" +else + install_vagrant_public_key +fi