Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: How to create multiple user account?

  1. #1
    Junior Member
    Join Date
    Jun 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default How to create multiple user account?

    I found the link to create multiple user account by typing out all the account. But how to create using linux shell scripting if i want to create 50 account which are almost the same but only difference is the user number and some other number is different which is in running order?

    Eg.
    First user will have the following details:
    Login name: user00
    Password: pwd00
    UID: 1000
    GID: 123
    Informational name: “Student Index 00”
    Home directory: /home/SI00
    Login shell: /bin/sh

    the last user will have the following details:
    Login name: user49
    Password: pwd49
    UID: 1049
    GID: 123
    Informational name: “Student Index 49”
    Home directory: /home/SI49
    Login shell: /bin/sh
    Last edited by droidwork; 8th June 2007 at 07:25 PM.

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,513
    Thanks
    17
    Thanked 804 Times in 511 Posts
    Rep Power
    10

    Default

    You need to use newusers command and a text file with this info.
    data.txt file
    Code:
    user00:pwd00:1000:123:Student Index 00:/home/SI00:/bin/sh
    user01:pwd00:1001:123:Student Index 01:/home/SI01:/bin/sh
    .....
    ...
    ..
    user49:pwd49:1049:123:Student Index 49:/home/SI49:/bin/sh
    Use following command to create above file:
    Code:
    for u in $(seq 00 05); do echo "user${u}:pwd${u}:$(expr 1000 + $u):123:Student Index ${u}:/home/SI${u}:/bin/sh"; done > data.txt
    Run command
    Code:
    newusers data.txt
    And you are done. more info @ my blog post: Linux: How to create multiple users accounts in batch | nixCraft

    PS: If you are doing this first time, make a backup of all all password related files aka /etc/passwd, /etc/group, /etc/shadow and others
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    Junior Member
    Join Date
    Jun 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    thank you.. lets say i wan to increase the user to say 80, which value should i change?

  4. #4
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,513
    Thanks
    17
    Thanked 804 Times in 511 Posts
    Rep Power
    10

    Default

    change seq parameters from 00 05 to 00 49
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  5. #5
    Junior Member
    Join Date
    Jun 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    sorry, i dont really get the code.. how come when create 50 user is 00 05 and 80 user is 00 49? Can explain the code part by part?
    Last edited by droidwork; 10th June 2007 at 02:15 PM.

  6. #6
    Senior Member raj's Avatar
    Join Date
    Jun 2005
    Location
    Hyderabad
    Posts
    566
    Thanks
    57
    Thanked 41 Times in 38 Posts
    Rep Power
    14

    Default

    Quote Originally Posted by droidwork View Post
    sorry, i dont really get the code.. how come when create 50 user is 00 05 and 80 user is 00 49? Can explain the code part by part?
    00-05 will create only 6 user from 00,01...05
    00-49 wil create 50 users from 00,01,02..49

    In short use
    Code:
    for u in $(seq 00 49); do echo "user${u}:pwd${u}:$(expr 1000 + $u):123:Student Index ${u}:/home/SI${u}:/bin/sh"; done > data.txt
    Raj
    Linux rulz.
    I have never turned back in my life ; I shall not do so today.. haha

  7. #7
    Junior Member
    Join Date
    Jun 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    somehow i cant get it to work.. it create only 1 funny account and not.. mayb can someone teach me step by step?

    i write the code in vi data.txt.. then after :wq!, use newusers data.txt.. is this the right way?
    Last edited by droidwork; 12th June 2007 at 04:31 PM.

  8. #8
    Senior Member raj's Avatar
    Join Date
    Jun 2005
    Location
    Hyderabad
    Posts
    566
    Thanks
    57
    Thanked 41 Times in 38 Posts
    Rep Power
    14

    Default

    Noop..

    Login as root user

    goto /tmp
    Code:
    cd /tmp
    To create 00-49 user type command:
    Code:
    for u in $(seq 00 49); do echo "user${u}:pwd${u}:$(expr 1000 + $u):123:Student Index ${u}:/home/SI${u}:/bin/sh"; done > data.txt
    Now you will see a file called data.txt. No need to create this file using vi text editor. It is genrated for you using above shell for loop.

    Now just add new users
    Code:
    newuser data.txt
    And you are done! Now user user1 can login with pwd1 and so on.
    Raj
    Linux rulz.
    I have never turned back in my life ; I shall not do so today.. haha

  9. #9
    Junior Member
    Join Date
    Jun 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    thank you very much.. anyway can tell me what does $(expr 1000 + $u): do? i know u is for the value.. and 1000 is the starting.. but what does expr for?
    Last edited by droidwork; 12th June 2007 at 05:41 PM.

  10. #10
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,513
    Thanks
    17
    Thanked 804 Times in 511 Posts
    Rep Power
    10

    Default

    Quote Originally Posted by droidwork View Post
    thank you very much.. anyway can tell me what does $(expr 1000 + $u): do? i know u is for the value.. and 1000 is the starting.. but what does expr for?
    Use to evaluate expressions such as expr 1 + 2 = 3

    ARG1 + ARG2 arithmetic sum of ARG1 and ARG2

    If $u=2, expr 1000 + ${u} = 1002

    Read man page of expr for upto-date information.
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to create Multiple directories at once?
    By eawedat in forum Shell scripting
    Replies: 2
    Last Post: 15th March 2010, 08:21 PM
  2. Create new user account in Ubuntu Linux from command line
    By sweta in forum Getting started tutorials
    Replies: 3
    Last Post: 7th February 2010, 12:15 PM
  3. Apache Create FTP File Uploading Account
    By fadu in forum Web servers
    Replies: 2
    Last Post: 4th July 2009, 11:30 AM
  4. Replies: 1
    Last Post: 2nd March 2009, 04:02 PM
  5. Replies: 0
    Last Post: 20th December 2006, 02:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •