Non-interactive password modification in Shell scripts and non-Password modification in shell scripts
Today, when I wrote a shell script, I found that the user's password needs to be set and the password is set to interactive. This is obviously not good in the script, So I went online to search for information, two common non-interactive password setting methods are found:
1: Use chpasswd
In fact, chpasswd uses the user to enter the 'user name: password' to change the passwords of a group of users. It is also a tool for changing passwords in batches. For details about the usage, see chpasswd usage.
Format: # echo Username: Password | chpasswd
Instance:
Add a doiido account with a password of 123456
# Echo doiido: 123456 | chpasswd
2: Use passwd and -- stdin combination
Passwd uses the terminal as the standard input by default, and -- stdin indicates that any file can be used as the standard input. The two combinations can directly change the password.
Format: # echo 'Password' | passwd -- stdin User Name
Instance:
Add a doiido account with a password of 123456
# Echo '000000' | passwd -- stdin doiido
In this way, you can change the password in non-interactive mode, but some embedded linux methods do not support this, you can use export.