Implementation requirements: Create user student1 to Student50, specify Group as student group! And each user needs to set a different password!
The script is implemented as follows:
#!/bin/bashfor i in ' seq 1 "do useradd-g student student$i; echo student$i | passwd student$i--stdin;done
Description: Linux under passwd parameters
--stdin
This option was used to indicate that passwd should read the new password from standard input, which can be a pipe.
so the way to automatically change user passwords under Linux is:
Echo password |passwd–stdin user name
"
-------------------Set the same password------------------------
#!/bin/bashpassword= "123456" for the USER in User1 user2 user3do useradd-m $USER echo-e "${password}\n${password}" | passwd $USERdone
"Description:
echo-n no newline output:
$echo-N "123"
$echo "456"
Final Output
123456
and not
123
456
ECHO-E Handling Special characters:
\ n Wraps and the cursor moves to the beginning of the line
OK, just such a simple script, you can batch generate accounts in the system. And the password is the same as the name of the account.
This is the use of the for Do statement.
This article is from "Linux rookie" blog, please be sure to keep this source http://490617581.blog.51cto.com/11186315/1765043
Batch build Linux users with shell scripts