today when writing a shell script to find that you need to set the user's password, and set the password is interactive, so in the script is obviously not very good, so the Internet to find information, found the following two common non-interactive password-setting methods:
1: Using CHPASSWD
CHPASSWD is actually through the user input ' user name: password ' To change a set of user's password, or a batch password can be modified tool, the specific usage see CHPASSWD usage, here only to do a simple introduction
Format:# echo User name: password | chpasswd
Instance:
Add a Doiido account with a password of 123456
# echo doiido:123456 | chpasswd
2: Use passwd and--stdin combination
passwd default is to use the terminal as the standard input, and--stdin means that you can use any file to do standard input, these two mates can directly modify the password
Format:# echo ' Password ' | passwd--stdin user name
Instance:
Add a Doiido account with a password of 123456
# echo ' 123456 ' | passwd--stdin doiido
This allows you to modify the password in non-interactive mode, but some embedded Linux do not support either way, you can use export to implement.
Non-interactive password change in Shell scripts