If you are looking for a quick and easily solution to changing your Linux passwd from a script, you have come to the right place. As you already know, the passwd command prompts the user to enter the desired password as well as a confirmation, but I have a solution that will change the password without these prompts.
Changing Linux Password In a Scriptable Way
echo <Desired Password> | passwd --stdin root
That’s all there is to it! No fancy bash script, no need to use Expect.
It’ll be better if there are some explaination of the commands, options, and prerequisite. for example, the passwd –stdin command will only work with root ID.