Answer the question
In order to leave comments, you need to log in
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
#!/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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question