Your requirement

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.

A solution

The 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

Attention!

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 ps ax)

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.

Linux knowledge

Questi articoli sono stati scritti dal fondatore di Checkmk molti anni fa.
Tuttavia, sono ancora validi e quindi li conserviamo sul nostro sito web.
Da allora Mathias ha sviluppato il software di monitoraggio che oggi è Checkmk.

Scopri di più