Linux: How To Create Multiple Users Accounts in Batch

The useradd command is used to create a new user or update default new user information from the command line. However, sometimes you need to create a large number of users or 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.

Task: Set Password

Type the following command to change or set user password:
echo "username:password" | newusers
For example, change user password for vivek user:
echo "vivek:myUltraSecretPassword" | newusers

Task: 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
Verify that your /etc/group, /etc/passwd and /etc/shadow files are updated:
less /etc/group
less /etc/passwd
less /etc/shadow

Recommend readings:

  • man page of the newusers command for more information.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 29 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
29 comments… add one
  • max Aug 22, 2006 @ 9:14

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

  • 🐧 nixCraft Aug 22, 2006 @ 11:21

    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 ..

  • Pradeep Jun 15, 2007 @ 3:12

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

  • Max Sep 12, 2007 @ 20:34

    One godawesome tip mate!


  • Anders Sep 24, 2007 @ 8:38

    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

  • 🐧 nixCraft Sep 24, 2007 @ 10:51


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

  • Anders Sep 26, 2007 @ 5:36

    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!


    Anders, Sweden

  • Terry Nov 6, 2007 @ 14:34

    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

  • 🐧 nixCraft Nov 6, 2007 @ 14:47


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

  • Terry Nov 6, 2007 @ 15:14

    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

  • Darren Jan 28, 2009 @ 20:33

    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?

  • ytuncez Feb 17, 2009 @ 9:27

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

  • henk the tank Mar 3, 2009 @ 11:54

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

    • Shruti Srivastava Feb 26, 2012 @ 11:10


      i am looking for automation script for deleting multiple users on multiple servers.
      As we have a central server through which we can access all the servers directly so if we can run the script on this server and can delete the users from all the other server.

      Let me know if you have any scripts for these.

  • Wilson Mar 25, 2009 @ 4:01

    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?

  • Scott Kunian Apr 24, 2009 @ 20:13

    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?

  • 🐧 nixCraft Apr 25, 2009 @ 0:11

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

  • desi Jun 11, 2009 @ 9:05

    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!

  • desi Jun 11, 2009 @ 9:31

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

  • Big May 5, 2010 @ 9:08

    If I’m requested to create 1000 users on Linux server, what would be the easiest way to do it?

  • John Brock Jul 12, 2010 @ 8:59

    On reading this page, I thought as usual, it would be so easy to create a few users…
    But ‘newusers’ is quite fussy. Your example above fails with “invalid line” for just the simple example.
    You MUST put a complete line in in the correct format.
    e.g. johnb:jknb1234:1001:500:mailuser:/home/mailuser:/bin/bash
    Also do this at the cli, not from Windwoes. This will add extra characters (cr) to every line.

    John Brock
    PS why don’t you sort the entries so that the latest comments are nearest the tutorial?

  • venkat Oct 1, 2010 @ 4:40

    how to create multipul users at time……..?
    how generate new users and passwords automatically by system and send to user mail ?
    how checking system performence…..?

  • Al Nov 1, 2010 @ 21:01

    Nice!! I was looking for this… one question: How can we create new groups in the same shell script and assign those new different groups to the different users in batch?

  • fraggie Dec 28, 2011 @ 10:34

    Hi All,
    I generally have to add many users on around 200 servers at the same time. its a hectic job. could anyone help me in creating a script for that. i use ssh to access servers but ssh may not be configured on some of the servers.
    Thanks in advance.

  • Shruti Srivastava Feb 26, 2012 @ 11:33

    Hi Fraggie,

    please share the script if you have for adding users at the same time….i do have the same issue of ssh to access the servers.

  • hans Sep 17, 2013 @ 15:24

    It seams that it does not work.
    On my system it is mandotory to put all emty fields in as in :

    echo “test3:testpwd:::::” | newusers

    See man page for details.

  • afsal Jul 13, 2016 @ 9:25

    how to creat multiple users using command ?

  • tom Oct 8, 2016 @ 19:28

    i wonder if this thread is still alive?

    perfectly simple script a beginner can understand.
    however, i wonder why the group ID# 513 is named both sales and student?
    how can that be?
    wouldn’t it be like group 513 is named Sales
    group 514 is named Students
    group 1001 is named Guest

    please explain…

    thanks in advance

  • frankfang Feb 24, 2017 @ 6:37


    sudo newusers testusers.txt
    *** Error in `newusers’: free(): invalid next size (fast): 0x09319cd0 ***
    *** Error in `newusers’: malloc(): memory corruption: 0x09319d00 ***

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum