creating bulk users in linux

Today I have configured NX server.
Now, Next task is to create users and really its very time consuming and boring task.

Usually you use useradd command to create a new user or update default new user information from command line.

So i have explore Linux and searched on Google , I have found few scripts to do this. But later I have found one good and easy solution.

Here is that,

Update and create new users in bulk.

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/bulk-user-add.txt
# chmod 0600 /root/bulk-user-add.txt


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

Append username and password:
sanjay:mypass99:555:555:Sanjay Singh:/home/Sanjay:/bin/bash
frampton:mypass99n:556:556:Frampton Martin:/home/Frampton:/bin/bash
----
--
---
barun:mypass99:560:560:Barun Ghosh:/home/Barun:/bin/bash

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

Read man page of newusers for more information.
May be I will automate entire procedure using a php

Comments

Andrea said…
Thanks Prabhat! Exactly what I was looking for. I'll share something with you, too. When kickstarting and using an "anaconda.cfg" file or such this has been handy to include in the %post section:

cat << EOF > /tmp/user.pwd
userid1:13z8NPbGls2Dc
userid2:CJafCFDqY7NWc
..
..
EOF

#>-----------------------------------------------------------------------
# EASY WAY to change multiple passwords
#--------------------------------------
# 1. Use the following command to create encrypted passwords:
# perl -e 'print crypt("mypassword", "XX"), "\n";'
# 2. Create a file, like /tmp/user.pwd above
# 3. Run the chpasswd command that updates passwords in batch mode
# for anyone in the /tmp/user.pwd file:

chpasswd -e < /tmp/user.pwd

Cheers,
Drea
Prabhat Kumar said…
Hi, Thanks its really Good way to save time if you have tons of users.

Popular posts from this blog

How do I Use the Linux Top Command?

IOPS measurement