Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I need to add 10 users by a script in Ubuntu 12.04.

That could reduces time by adding users manually , and i can apply this script on other desktop .

Each user will has a specific user and in specific group.

Any idea?

share|improve this question
    
possible duplicate of Shell script to automate user addition –  Ron May 8 at 13:54

4 Answers 4

Open a terminal and type: vim /tmp/name to create a file and the names of the users: eg:

vim /tmp/name
mika
mery
etc

Create User with Home Dir and default shell:

for i in `cat /tmp/name`; do useradd -m -d /home/$i -s /bin/bash $i; done

Create password for each user:

for i in `cat /tmp/name`; do passwd $i; done
share|improve this answer

Look at the answer here,which says unless you have a whole lot of users to add the best way is to use adduser (for adding users) and usermod (for adding a user to a group) which takes care of a lot of things. If you still wish for some pre-made script, there is one here and another one here, but I do not know if they really work for you

share|improve this answer

It is my solution. I created file /tmp/userlist and added all users name, after completion of script it will create users and you can find user name and given random password in file /tmp/userlist-created. I know it is not perfect solution.

root@demobox:/root : cat /tmp/userlist
xyz1
zyz2
zyz3

root@demobox:/root : cat demo.sh
#!/bin/bash

if [ -f /tmp/userlist ]
then
for i in $(cat /tmp/userlist)
do
if [ -f /usr/bin/pwgen ]
then
PASSWORD=$(pwgen -1 -s 16)
else
PASSWORD=$(cat /dev/urandom | tr -dc "passwordNSR!@#$%0-9" | fold -w 9 | head -1)
fi
useradd -s /bin/bash -d "/home/$i" -m -p "$PASSWORD" "$i"
echo "$i --------- $PASSWORD" >>/tmp/userlist-created
done
else
echo "File /tmp/userlist not found"
fi
chmod 0600 /tmp/userlist-created

root@demobox:/root : ./demo.sh

root@demobox:/root : cat /tmp/userlist-created
xyz1 --------- FivSHfdbDCRffhc7
zyz2 --------- AIjFjE0bv3FslHnp
zyz3 --------- JazcGcKYp2Y0I3Rk

root@demobox:/root : egrep "xyz1|zyz2|zyz3" /etc/passwd
xyz1:x:9016:100::/home/xyz1:/bin/bash
zyz2:x:9017:100::/home/zyz2:/bin/bash
zyz3:x:9018:100::/home/zyz3:/bin/bash
share|improve this answer

You could try this, I suppose.

for user in {1..200}; do
    echo "Creating user$user"
    cat <<EOF | adduser --gid 500 user$user
password
password
user$user







EOF
done
share|improve this answer
    
here all users are in the same group. –  guntbert Jan 25 '14 at 22:21
    
@guntbert They were in the OP's answer, as well. All were in 513 in the OP's. –  minerz029 Jan 25 '14 at 22:33
    
true, but the question stated: "Each user will has a specific user and in specific group." - which you could achieve by omitting the --gid 500 part. –  guntbert Jan 26 '14 at 11:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.