How to set user passwords using passwd without a prompt?
Try usermod:
usermod --password PASSWORD USERNAME
The only thing is this needs a pre-encrypted password string which you'd have to generate first.
You should look at the chpasswd
command (if available in your linux flavor):
echo 'userid:newpasswd' | chpasswd
Or, you can cat a file listing userid:passwd for each account on a separate line.
That's it.
Inspired by Eric Smith's idea, combining openssl passwd
and usermod -p
command worked. Generate hashed value of password along with salt value.
$ openssl passwd -1 -salt 5RPVAd clear-text-passwd43
$1$5RPVAd$vgsoSANybLDepv2ETcUH7.
Then, copy the encrypted string to usermod. Make sure to wrap it with single quote.
$ usermod -p '$1$5RPVAd$vgsoSANybLDepv2ETcUH7.' root
Check it out in shadow file.
$ grep root /etc/shadow
root:$1$5RPVAd$vgsoSANybLDepv2ETcUH7.:17774:0:99999:7:::