K
K
koshelevatamila47412021-12-22 17:04:44
linux
koshelevatamila4741, 2021-12-22 17:04:44

How to encrypt password and pass it to smbpasswd?

I create users using information from a csv file and would like to encrypt passwords, make the script safer.
I found such a code, but it is not clear how to correctly transfer passwords to smbpasswd; it turns out that they need to be decrypted back, otherwise I will not be able to log in under these accounts.

sudo useradd -p $(openssl passwd -1 $PASS) $USERNAME

At the moment, this is the code, but is it safe to pass passwords to smbpasswd in echo?
#!/bin/bash
echo "CSV name:"
read CSVFILE
if [ -f $CSVFILE ]
then
exec < $CSVFILE
while
read line
do
name=$(echo $line | awk -F, '{print $1'})
login=$(echo $line | awk -F, '{print $2'})
password=$(echo $line | awk -F, '{print $3'})
passwd --stdin <<< "$password"
group=$(echo $line | awk -F, '{print $4'})
email=$(echo $line | awk -F, '{print $5'})
day=01
month=01
year=2022
path="/home/sambaShare/"
mkdir $path$login
useradd "$login" -g "$group" -p "$passwd" -d "$path$login" -c "$name $email" -e "$year-$month-$day"
chown -R "$login":users "$path$login"
chmod -R 0700 "$path$login"
(echo "$passwd"; echo "$passwd") | smbpasswd -s -a "$login"
done
else
echo "doesnt exist"
fi

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2021-12-22
@ky0

Inside the echo script is fine. Passwords are temporary, which users will then have to change at the first login, right?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question