Linux batch User Creation and deletion tutorials, linux User Creation tutorials
Create users in batches as follows:
First, you need to create a xxx.txt file and write the user you want to create in this text. Note: each user writes a line break.
Vim user.txt
User1
User2
User3
# Create a xxx. sh shell script, and then use the forcycle to traverse the created user.txt. The following is a shell script:
#! /Bin/bash
# Here I create shell scripts and txt files in the same directory. If they are not in the same directory, note the path
For user in 'cat user.txt'
Do
Useradd $ user
# Passwd -- stdin indicates no interaction. Enter the password directly.
Echo $ user | passwd -- stdin $ user & >>/dev/null
Echo "The user useradd success! "
Done
Delete users in batches
# After reading the above batch create users, it is easy to delete users in batches!
# The principle is basically the same, but a command is different, so I will not explain it much.
# The following is a shell script
#! /Bin/bash
Grep "/bin/bash"/etc/passwd | grep-v "root" | cut-d ":"-f 1> 2.txt
For user in $ (cat./2.txt)
Do
Userdel-r $ user
Echo "del $ user OK"
Done
Rm-rf 2.txt