Linux: How to create multiple users accounts in batch

Usually you use useradd command to create a new user or update default new user information from command line. However, let us say you want to create a large number of users or if you want to import usernames from a text file. You can use newusers command, which update and create new users in batch.

This is useful at universities or large corporate Linux networks. Adding users in batch saves the time.

Update and create new users in batch

newusers command reads a file of user name and clear-text password pairs and uses this information to update a group of existing users or to create new users. Each line is in the same format as the standard password file.

This command is intended to be used in a large system environment where many accounts are updated at a single time (batch mode). Since username and passwords are stored in clear text format make sure only root can read/write the file. Use chmod command:
# touch /root/batch-user-add.txt
# chmod 0600 /root/batch-user-add.txt

Create a user list as follows. Open file:
# vi /root/batch-user-add.txt

Append username and password:
user1:password:1001:513:Student Account:/home/user1:/bin/bash
user2:password:1002:513:Sales user:/home/user2:/bin/bash
user100:password:1100:513:Sales user:/home/user100:/bin/bash
tom:password:1110:501:Guest Account:/home/guest:/bin/menu
jerry:password:1120:501:Guest Account:/home/guest:/bin/menu

Now create users in batch:
# newusers /root/batch-user-add.txt

Read man page of newusers for more information. Next time I will write how to automate entire procedure using a shell script :)

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 18 comments… read them below or add one }

1 max 08.22.06 at 9:14 am

I’m just wondering what could be a typical content in the ‘…:/bin/menu’ file.

2 nixcraft 08.22.06 at 11:21 am

A shell or perl script that displays basic options for guest like open mc file browser, a mail client, shell access or offers help etc ..

3 Pradeep 06.15.07 at 3:12 am

Thanks for that tutorial.
I learned to add multiple users at one go..
Thanks a lot..
neat and simple .

4 Max 09.12.07 at 8:34 pm

One godawesome tip mate!

thanx!

5 Anders 09.24.07 at 8:38 am

Extremly nice script! Though, I have a different issue I’m trying to create a work-around for. Im administrating mailaccounts and soon I need to add another 2000 mailaccounts to the system. This is not something done in a few minutes and I was wondering if someone can help me create/have a script/have an idea on how to solve this.

The mailaccounts start with donw and then 4 numbers, ex donw2518, donw2519 etc etc.

So, I need a script that can add users with an incremental count on the username.

Appologize for my bad grammar ;-P

//Anders, Sweden

6 vivek 09.24.07 at 10:51 am

Anders,

A few months back someone posted same question on our Linux support forum. I’ve posed solution for the same.

7 Anders 09.26.07 at 5:36 am

Vivek, I owe you bigtime. Thanks a BUNCH! ;-P
If you are skilled with named/DNS, please let me know, I have another problem that I need help with.

Thanks again, huuuuge thanks!

Regards,

Anders, Sweden

8 Terry 11.06.07 at 2:34 pm

This is a great method for adding multiple users, but I found an issue whereby default user profile settings are not created, ie the contents of /etc/skel are not copied to the user’s home directories. Is there a way to have this enabled, or does this require a separate step

9 vivek 11.06.07 at 2:47 pm

Terry,

Noop, you need to write a custom script using perl or python

10 Terry 11.06.07 at 3:14 pm

Thanks Vivek, do you happen to have something handy? otherwise no worries, most of the accounts I am creating are for ftp use and will not be logging on anyway

11 Darren 01.28.09 at 8:33 pm

Hi, I am trying to create multiple accounts at once. I created a file with all the usernames and commands, but when i run it (./filename) it gives errors stating that the username is invalid. When I run the command to add a user it works. Can someone help me?

12 ytuncez 02.17.09 at 9:27 am

How do you create user id and group id automatically this command

13 henk the tank 03.03.09 at 11:54 am

Can you also make a script for deleting multiple users? and how can i get it work in Suse?

14 Wilson 03.25.09 at 4:01 am

I have followed the guide and it can create multiple users in one times…but when I test login the new users, I found got this error:

“Your session only lasted less than 10 seconds. If you have not logged out yourself, this could mean that there is some installation problem or that you may be out of diskspace. Try logging in with one of the failsafe sessions to see if you can fix this problem.”

May I know what happen? Or I miss some steps in creating new users with above guide?

15 Scott Kunian 04.24.09 at 8:13 pm

This workd great for creating the user with one issue I can’t seem to figure out.

My text file was formetted like this
username1:password1:1001:100:User Name:/home/username1:/bin/ksh

The problem I had is that the Login Shell ended up being some newly created /bin/ksh with a odd symbol tacked onto the end. So I still had to go into each user and change the shell. For testing I tried to add a : to the end of each line and that only through an error. I tested again by making the shell /bin/bash and that duplicated the same issue, by createing a different /bin/bash with an odd symbol at the end.

Any thoughts?

16 Vivek Gite 04.25.09 at 12:11 am

Refer to your local newusers man page. It may be latest or old version…

17 desi 06.11.09 at 9:05 am

hi to everyone!
i try this tutorial but when i try to login to my squirrelmail it shows error messages from IMAP server. every command was executed but the problem is when i try to login to my webmail. what can i do? can anyone help me!

18 desi 06.11.09 at 9:31 am

i think it has to do because when a user is created its home folder does not contain maildir folder. what should i do?

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , ,

Previous post: Lighttpd install and configure Webalizer statistics software

Next post: Linux installations equals profit suggest the study