Shell Script First-Custom create user and batch create user
1. build Linux users with shell scripts
# vim/root/user.sh
#!/bin/bash
#通过脚本自定义创建用户
read-p " Please enter the user name you want to create : " $
Useradd $
read-p " Please set the user password: " $
Echo " $ " | passwd--stdin $ >/dev/null
#/root/user.sh or # cd/root #./user.sh or #bash user.sh or #. user.sh
#####################################################################
2. create a batch of Linux users with scripts
# vim/root/piuser.sh
#!/bin/bash
#通过脚本批量创建用户
prefix= "Stu" : Define user name prefix
I=1
While [$i-le 20]
Do
useradd ${prefix} $i : Added username: prefix + number
echo "123456" | passwd--stdin ${prefix} $i &>/dev/null
or userdel-r ${prefix} $i &>/dev/null: delete users in bulk
let i++
D One
or Create user stu1 to stu50, specify Group as student group! Each user needs to set a different password!
#!/bin/bash
For i in ' seq 1 50 '
Do
useradd-g Student Stu$i ;
echo stu$i | passwd stu$i--stdin
Done
Shell script first-custom create user and bulk create user