You want to change the password of root or another user by using a script. This should be performed without the need for user interaction.
passwd command reads the password from the standard input if you specify the
--stdin option. Examples:
root@linux# echo 'geheim' | passwd --stdin root root@linux# echo '73/3g78' | passwd --stdin mk
This procedure may involve security risks, as the password is transferred in clear text. Among other things, the password will be visible:
- in the Bash history, if you enter the command interactively
- for a short time in the process list (command
However, this solution may still be suitable, for example, if no other users are logged on to the machine at the time of the password generation.