How to assign password to user in shell script

不言
Release: 2019-03-22 14:41:25
Original
3325 people have browsed it

This article introduces to you how to assign passwords to users in shell scripts. Let’s look at the specific content below.

How to assign password to user in shell script

Let’s take a look at the command first

echo <password> | passwd –stdin <username>
Copy after login

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
Copy after login

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
Copy after login

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&#39;t match...."
    fi
done
echo $pwd1 | passwd --stdin user
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template