added generated password for hosts users

This commit is contained in:
mischa 2020-05-22 19:04:47 +02:00
parent fa336745be
commit ce2b228332
1 changed files with 9 additions and 4 deletions

View File

@ -23,6 +23,7 @@
# 2019/05/31 added: check for OpenBSD 6.6 vmctl command line syntax change # 2019/05/31 added: check for OpenBSD 6.6 vmctl command line syntax change
# 2019/09/29 added: doas.conf for pkill option # 2019/09/29 added: doas.conf for pkill option
# 2020/05/10 changed: includes all install sets, inline with sysupgrade # 2020/05/10 changed: includes all install sets, inline with sysupgrade
# 2020/05/22 changed: set the hosts password for the user
# #
use 5.024; use 5.024;
use strict; use strict;
@ -239,9 +240,13 @@ sub create_accounts {
my $id = getpwnam("$_owner"); my $id = getpwnam("$_owner");
if (! $id) { if (! $id) {
my $output = qx(/usr/sbin/useradd -m -G $_group $_owner); my $_pass = qx(jot -rcs '' 20 39 126);
chomp($_pass);
my $_encrypted_pass = qx(encrypt $_pass);
chomp($_encrypted_pass);
my $output = qx(/usr/sbin/useradd -m -G $_group -p "$_encrypted_pass" $_owner);
open my $fh_authorized, ">>", "/home/$_owner/.ssh/authorized_keys"; open my $fh_authorized, ">>", "/home/$_owner/.ssh/authorized_keys";
printf $fh_authorized "%s\n", $_sshkey; printf $fh_authorized "%s %s\n", $_sshkey, $_pass;
close $fh_authorized; close $fh_authorized;
printf "%16s %s account created\n", $_instance, $_owner; printf "%16s %s account created\n", $_instance, $_owner;
} }