summaryrefslogtreecommitdiff
path: root/rpi-set-sysconf
diff options
context:
space:
mode:
authorGunnar Wolf <gwolf@gwolf.org>2020-08-15 00:01:54 -0500
committerGunnar Wolf <gwolf@gwolf.org>2020-08-15 00:01:54 -0500
commitd2ed03378e193db4707c3c0e4b5e51c5ccd2c68f (patch)
tree1309f78cbcf1c30bb5c772215cae72e9ace066fd /rpi-set-sysconf
parentc2bc44541a6cdc45faef5ef0eba174b0051ea2bb (diff)
Allow setting ssh authorized key for root, so pi can be configured via network
Merging changes proposed by Nik LaBelle in merge request #22
Diffstat (limited to 'rpi-set-sysconf')
-rw-r--r--rpi-set-sysconf23
1 files changed, 23 insertions, 0 deletions
diff --git a/rpi-set-sysconf b/rpi-set-sysconf
index 2bd2904..70da73a 100644
--- a/rpi-set-sysconf
+++ b/rpi-set-sysconf
@@ -24,6 +24,26 @@ if (my $pass = delete($conf->{root_pw})) {
close($pipe);
}
+if (my $root_authorized_key = delete($conf->{root_authorized_key})) {
+ my $fh;
+ logger('debug', "Adding key to root's authorized_keys");
+ if(! -d "/root/.ssh") {
+ if(!mkdir("/root/.ssh", 0700)) {
+ my $err = sprintf("Could not create /root/.ssh directory: %s", $!);
+ logger('error', $err);
+ die $err;
+ }
+ }
+
+ unless ($fh = IO::File->new('/root/.ssh/authorized_keys', 'w', 0600)) {
+ my $err = $!;
+ logger('error', "Could not write /root/.ssh/authorized_keys: $err");
+ die $err;
+ }
+ $fh->print($root_authorized_key);
+ $fh->close;
+}
+
if (my $name = delete($conf->{hostname})) {
my $fh;
logger('debug', "Setting hostname to '$name'");
@@ -113,6 +133,9 @@ q(# This file will be automatically evaluated and installed at next boot
# for a passwordless login)
#root_pw=FooBar
+# root_authorized_key - Set an authorized key for a root ssh login
+#root_authorized_key=
+
# hostname - Set the system hostname.
#hostname=rpi
));