Interactively change password 1. SSH remote to the host; 2. Switch to root account;
[generally switch to root for password modification, if the ordinary user to modify their own password, to enter the original password, and then the new password to meet the complexity of the OK];
3. passwd
username
Use passwd username to modify the username password;
Using this command, you will be prompted to enter the interactive interface, the password can be entered.
To modify a password using a script
Many times we may need to remotely execute the script on the server to modify the account password, there is no way to interact.
There are two ways to change your password at this point:
Mode 1:
echo "password" | passwd testuser --stdin > /dev/null 2>&1
Mode 2:
echo testuser:password|chpasswd
Note:
Double quotes for cipher strings, optional, see above 方式1
and 方式2
examples
If the password contains a $ character, it needs to be escaped with a backslash, such as:
echo testuser:password\$|chpasswd
转自1190000003866142 特别感谢他在我职业生涯对我的帮助。
Linux changes passwords through shell scripts