Linux Bulk Create user and bulk delete users
The following is a batch creation of users:
#首先我们需要创建一个xxx. txt file, write the user we created in this text, and note that each user needs to be wrapped.
Vim User.txt
User1
User2
User3
#创建一个xxx the. Sh shell script, and then use the For loop to iterate through the created User.txt, which is the shell script:
#!/bin/bash
#我这里是把shell脚本和txt文件创建在同一个目录下, if you are not in the same directory, be aware of the following path
For the user in ' Cat user.txt '
Do
Useradd $user
#这里的passwd--stdin means: Non-interactive, direct input password
echo "123" | passwd--stdin $user
echo "The User Useradd success!"
Done
The following is a bulk delete user
#看了以上的批量创建用户, then it's easy for the next batch to delete the user!
#原理基本上是一样的, it's just a different order, I don't have much to explain.
#以下是shell脚本
#!/bin/bash
For the user in ' Cat user.txt '
Do
Userdel-r $user
echo "The User deletc success!"
Done
Linux Bulk Create user and bulk delete users