I’m writing a shell script to automatically add a new user and update their password. I don’t know how to get passwd to read from the shell script instead of interactively prompting me for the new password. My code is below.
adduser $1 passwd $1 $2 $2
from "
man 1 passwd":So in your case
Your
passwdcommand may not have a--stdinoption: use thechpasswdutility instead, as suggested by ashawley.If you use a shell other than bash,
echomight not be a builtin command, and the shell will call/bin/echo. This is insecure because the password will show up in the process table and can be seen with tools likeps.In this case, you should use another scripting language. Here is an example in Perl: