Allow setting ssh authorized key for root, so pi can be configured via network

Merging changes proposed by Nik LaBelle in merge request #22
This commit is contained in:
Gunnar Wolf 2020-08-15 00:01:54 -05:00
parent c2bc44541a
commit d2ed03378e
2 changed files with 26 additions and 0 deletions

View File

@ -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
));

View File

@ -24,6 +24,9 @@
# 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