Adding and Deleting Users is a simple task for every Linux system administrator. the tricky thing is that if you want to add dozens, hundreds, or even thousands of users, we are unlikely to add useradd one by one, so we must find a simple method to create a large number of users. Linux provides a tool to create a large number of users, allowing you to create a large number of users immediately, as follows:
Method 1:
Step 1: edit a text user file. Each column is written in the format of the/etc/passwd password file. Note that the user name, uid, and home directory of each user cannot be the same, the password column can be left blank or enter the X number. The content of user.txt in a sample file is as follows:
User001: 500: 100: User:/home/user001:/bin/bash
User002: 501: 100: User:/home/user002:/bin/bash
User003: 502: 100: User:/home/user003:/bin/bash
User004: 503: 100: User:/home/user004:/bin/bash
User005: 504: 100: User:/home/user005:/bin/bash
User006: 505: 100: User:/home/user006:/bin/bash
.........
Step 2: run the command/usr/sbin/newusers as root to import data from the user file user.txt, and create the user:
# Newusers <user.txt
Then, run vipw or VI/etc/passwd to check whether the data of these users is displayed in the/etc/passwd file and whether the user's home directory has been created.
Step 3: run the/usr/sbin/pwunconv command to decode the shadow password generated by/etc/shadow and write it back to/etc/passwd, delete the shadow password column of/etc/shadow. This is to facilitate the next step in password conversion, that is, to cancel the shadow password function first.
# Pwunconv
Step 4: edit the password reference file for each user. The content of the example file passwd.txt is as follows:
User001: Password
User002: Password
User003: Password
User004: Password
User005: Password
User006: Password
...........
Step 5: run the command/usr/sbin/chpasswd as root to create the user password, chpasswd writes the password encoded by the/usr/bin/passwd command to the/etc/passwd password column.
# Chpasswd <passwd.txt
Step 6: confirm that the password is encoded into the/etc/passwd password column and run the/usr/sbin/pwconv command to encode the password as shadow password, write the result to/etc/shadow.
# Pwconv
In this way, a large number of users are created. Then, you can go to/home to check whether the permission settings of these users in the home directory are correct, and log on to verify that the user password is correct.
Method 2:
Create user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, and set the password to pass1, pass2, and pass3.
Directly enter the command for user in 1 2 3 4 5 6 7 8 9 10 \ user as the variable do \ loop start useradd "user" $ user \ create user echo "pass" $ user | passwd -- stdin "user" $ user \ set password done \ complete
Method 3:
There is a file containing the name of the company's network management, requiring the creation of an account with the user name as the file list, and requiring the password to be the user name + 123
For user in 'less userfile' \ Use the content in userfile as the variable, and use "'" to include do \ To start useradd $ user \ To create user echo $ user "123 "| passwd -- stdin $ user \ create user done \ complete