First, batch create users
Batch creation of users can be achieved by command newusers.
The use of this command is NewUsers file.txt (a text file)
Storing user information in a text file that needs to be added in bulk
But there are requirements for formats
Format:
Pw_name:pw_passwd:pw_uid:pw_gid:pw_gecos:pw_dir:pw_shell
Its format is the same as the format of the/etc/passwd file
However, when finished newusers batch created users, there is no user template file in the generated home directory, these files need to be copied manually
Manual operation is cumbersome, so use scripts to execute:
- #!/bin/bash
- NewUsers $1 #该参数为用户文本文件的完整路径
- User_add = ' cat $1 | grep $i | cut-d:-f1 '
- For I in ' cat $1 | awk-f ': ' {print $6} ' #循环家目录
- Do
- If ' cat/etc/passwd | grep $i | Wc-l '! = 1
- echo "User Add Error, both or more User used same home directory! $i " #如果有两个家目录则报错
- Exit(1)
- Fi
- Cp-r/etc/skel $i
- Chown-r $user _add. $user _add $i
- Done
Second, batch change user password
By command CHPASSWD to achieve
Implementation method:
Cat Passwd.txt | CHPASSWD #直接实现修改密码
Where the Passwd.txt file format is as follows:
File format: User:password
User2:password2
Linux Bulk Add users and bulk change passwords