This article introduces to you how to assign passwords to users in shell scripts. Let’s look at the specific content below.
Let’s take a look at the command first
echo <password> | passwd –stdin <username>
For example:
Use the following command to change the password of user jack in the shell script . For example, we use the string password as the password.
cho "password" | passwd --stdin user
Assign user to enter password:
Use the following command to enter password from user and assign to user user.
read -p "Enter Password for User jack: " pwd echo $pwd | passwd --stdin user
In addition, we can also prompt the user to enter the password twice to confirm that the user has entered the correct password. Use the following command to enter the password twic from user and assign it to user user.
while : do read -p "Enter Password for User user: " pwd1 read -p "Confirm Password for User user: " pwd2 if [ "$pwd1" == "$pwd2" ] then break else echo "Password and Confirm password doesn't match...." fi done echo $pwd1 | passwd --stdin user
This article has ended here. For more other exciting content, you can pay attention to the Linux Tutorial Video column of the PHP Chinese website!
The above is the detailed content of How to assign password to user in shell script. For more information, please follow other related articles on the PHP Chinese website!