summaryrefslogtreecommitdiff
path: root/root-ssh-authorized-key.configure
blob: 7c41218aebc64fd9a6bafe8283a1405320debe8d (plain)
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
#!/bin/sh
#
# Copyright (C) 2014  Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# This is a "morph deploy" configuration extension to add an SSH key as
# an authorized key for the root account. This means that SSH access to
# the machine as root is possible as soon as the machine boots, instead
# of requiring an initial manual login. This functionality is used by
# Baserock's automated tests.
#
# The following configuration variable should point at a file
# containing an SSH public key: ROOT_SSH_PUBKEY

set -eu

OS="$1"

echo "Add SSH public key for root user"

# We don't use 'ssh-copy-id' because it requires the machine to be
# running and available over SSH already. Luckily the manual case is
# simple.
mkdir -p "$OS/root/.ssh"

target="$OS/root/.ssh/authorized_keys"

echo "# Added by Baserock root-ssh-authorized-key.configure" >> "$target"
cat "$ROOT_SSH_PUBKEY" >> "$target"
echo >> "$target"