Polls

Topics

Linux: How to create multiple users accounts in batch

Posted by Vivek on Monday August 21, 06 @1:13 pm

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 stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in...

Discussion on This Article:

  1. max Says:

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

  2. nixcraft Says:

    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 Says:

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

  4. Max Says:

    One godawesome tip mate!

    thanx!

  5. Anders Says:

    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 Says:

    Anders,

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

  7. Anders Says:

    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 Says:

    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 Says:

    Terry,

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

  10. Terry Says:

    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

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

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

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , ~ Last updated on: September 24, 2007

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.