Add user accounts in batch

This is a perl script for adding user and group accounts in batch under linux, It is released under the terms of the GNU Public License

In fact, there is already a newusers command from shadow-utils which can do this. However, it requires the input file to be in the format of passwd(5).As a result, I must manually specify the uid,gid,shell,…etc for the user to be created,that’s boring ! It will be better if I can make the system choose such info for me,like the useradd command.So I write this script.

To add groups, you just need to place the group name in a file,one group per line

To add users, you just need to place user info in a file, one per line,with the format:

login:user name:primary group:supplementary groups

Note: primary group and supplementary groups may be omitted,but the the colon(:) must be kept.
An example users file:

#file: users.txt
user1:Test user1:group1:other_group1,othergroup_2
user2:Test user2:group2:
user3:Test user3::

An example groups file:

#file: groups.txt

then, run this script,pass it the user file, or group file, add a default password for all new users:

./ --userfile=users.txt --groupfile=groups.txt --password=secret

You can download it from here

This entry was posted in Programming, System Administration and tagged . Bookmark the permalink.

Leave a Reply