1754320 Members
3208 Online
108813 Solutions
New Discussion юеВ

adding 500 users

 
SOLVED
Go to solution
Binu_5
Regular Advisor

adding 500 users

Hi

I have a requirement in adding 500 users in a linux systems ...Is there any easy way that I can do it instead of doing manullay

Thanks
Binu
5 REPLIES 5
Gopi Sekar
Honored Contributor

Re: adding 500 users


if the user names are some sort of continuous like (user1, user2 etc) then you should be able to do it with simple scripting.

otherwise also, if you have list of usernames in a text file then you could use following script:

## script assumes you have one username in a line, the file name is assumed to be user-list
## It adds the users using useradd command, creates the home directory (as per username)
## sets the group id as 100 (users group), sets the login shell as /bin/bash
## after creation sets the password as same as username.

#!/bin/bash

while read userid
do
echo "Creating useraccount $userid"

useradd -m -g 100 -s /bin/bash $userid
if [ $? == 0 ]; then
echo "created successfully"
else
echo "failed to create user account $userid"
exit
fi

echo $userid | passwd --stdin $userid

done < user-list




Hope this helps,
Gopi
Never Never Never Giveup
LiPEnS
Valued Contributor

Re: adding 500 users

Hi
do this in script:

#!/bin/bash
i=1000
while test $i -lt 1500
do
/usr/sbin/useradd -u $i -g group -d /home/user$i -s /bin/bash -m user$i
done

Regards
Muthukumar_5
Honored Contributor

Re: adding 500 users

As a root user you can use useradd utility to add users with shell scripting loop.

index=1
while [[ ${index} -lt 501 ]]
do
/usr/sbin/useradd
let index=index+1
done

Post your requirement of user details as,

user Id from to.
group name / group ID
home directory
etc.
details to give exact script.

hth.
Easy to suggest when don't know about the problem!
Binu_5
Regular Advisor

Re: adding 500 users

Hi Gopi

I want the user to be like user1 to user500 no need of taking from user-list
where shall i mention that

Thanks
Binu
Gopi Sekar
Honored Contributor
Solution

Re: adding 500 users

Then change the script as follows (only changes in the while loop and setting up userid variable).

change the username however you want(next to do statement)


#!/bin/bash

let i=1
while [ $i -le 500 ]
do
userid="user"$i
let i=$i+1

echo "Creating useraccount $userid"

useradd -m -g 100 -s /bin/bash $userid
if [ $? == 0 ]; then
echo "created successfully"
else
echo "failed to create user account $userid"
exit
fi

echo $userid | passwd --stdin $userid

done


Hope this helps,
Gopi
Never Never Never Giveup