I am building a script to fully automate a VPS setup, and I need to change the root password. I would like to avoid typing it as the script is running through SSH.Is there a way to redirect an arbitrary value to the input of passwd command?EDITI know for passwd < passwd_file.txt containing the password twice... I would like to know if there is a more elegant way as it seems a little bit clumsy to use a temp file for this purpose.
Change password in headless mode
shell;ubuntu;io redirection;password
You don't say what version of UNIX you're using, but on Linux the passwd(1) man page shows:   --stdin          This option is used to indicate that passwd should read the  new          password from standard input, which can be a pipe.So all you have to do is run:echo 'somepassword' | passwd --stdinEdit to add: more portable is chpasswd which exists on (at least) both Red Hat and Ubuntu:echo 'someuser:somepassword' | chpasswdSee the man page.