Page 1 of 6 123 ... LastLast
Results 1 to 10 of 56

Thread: Creating multiple user logins assigned to multiple groups at one time

  1. #1
    Join Date
    Feb 2011
    Location
    Atlanta, GA
    Posts
    34

    Question Creating multiple user logins assigned to multiple groups at one time

    I have a single computer for our building which various building residents need to be able to log into with their own names. I have a listing of all the usernames (over 300 users) and passwords in a text file. I did some research and found that it should be possible to add them using a script, but there were so many changes whenever a possible script was posted that I had trouble following the message threads to get a coherent final script to use.

    So far, here is what I have found, and I hope this works in Suse 11.3:
    But it doesn't say anything about adding to more than one group? I know if I add thru YAST, it adds to users, and then by default adds to the additional group "video" (is this for them to be able to log in with the gui?)

    However, the script I found shows one user group, but didn't say what to do if I needed to add to more than one group? Or will adding these users via the list auto-add them to video because of the default in YAST? Or do I need to put both groups, maybe comma-separated or something?

    I am a mostly newbie here, and I really don't do code, but I can follow directions if they're explained well enough!

    Here's what I found:

    Use chmod command:
    Code:
    # touch /root/batch-user-add.txt
    # chmod 0600 /root/batch-user-add.txt

    Create a user list as follows. Open file:
    Code:
    # vi /root/batch-user-add.txt
    Append username and password following the format provided of:
    Code:
    loginname:password:uid:gid:comment:home_dir:shell
    *** does this mean simply copy/paste the below user info into the batch-user-add.txt file?

    also, what happens if you don't define shell? and which shell is better?

    Code:
    Unit0106:concorderesident:1201:1001:Unit 106:/home/Unit0106:/bin/bash
    Unit0107:concorderesident:1202:1001:Unit 107:/home/Unit0107:/bin/bash
    Unit0108:concorderesident:1203:1001:Unit 108:/home/Unit0108:/bin/bash
    Unit0109:concorderesident:1204:1001:Unit 109:/home/Unit0109:/bin/bash
    Unit0201:concorderesident:1205:1001:Unit 201:/home/Unit0201:/bin/bash
    Unit0202:concorderesident:1206:1001:Unit 202:/home/Unit0202:/bin/bash
    Unit0203:concorderesident:1207:1001:Unit 203:/home/Unit0203:/bin/bash
    Unit0204:concorderesident:1208:1001:Unit 204:/home/Unit0204:/bin/bash
    Unit0205:concorderesident:1209:1001:Unit 205:/home/Unit0205:/bin/bash
    Unit0206:concorderesident:1210:1001:Unit 206:/home/Unit0206:/bin/bash
    Unit0207:concorderesident:1211:1001:Unit 207:/home/Unit0207:/bin/bash
    Unit0208:concorderesident:1212:1001:Unit 208:/home/Unit0208:/bin/bash
    Unit0209:concorderesident:1213:1001:Unit 209:/home/Unit0209:/bin/bash
    Unit0210:concorderesident:1214:1001:Unit 210:/home/Unit0210:/bin/bash
    Unit0301:concorderesident:1215:1001:Unit 301:/home/Unit0301:/bin/bash
    Unit0302:concorderesident:1216:1001:Unit 302:/home/Unit0302:/bin/bash
    Unit0303:concorderesident:1217:1001:Unit 303:/home/Unit0303:/bin/bash
    Unit0304:concorderesident:1218:1001:Unit 304:/home/Unit0304:/bin/bash
    Unit0305:concorderesident:1219:1001:Unit 305:/home/Unit0305:/bin/bash
    Unit0306:concorderesident:1220:1001:Unit 306:/home/Unit0306:/bin/bash

    Now create users in batch:
    Code:
    # newusers /root/batch-user-add.txt
    Ok, this seems fairly straightforward so far, and the command line doesn't intimidate me too much, as I grew up on DOS.

    Can someone tell me if I'm doing this right? And if I need to worry about whether it's only adding to the group "users" and not to "video" ? Or how to add to both?

    and final question, a quick way to set all those newly created users to require them to change their password on first login, and then to never have the password expire afterwards? (hopefully without resetting my root password in the process?)

    Any help on this is greatly appreciated! Thanks!

  2. #2
    Join Date
    Feb 2011
    Location
    Atlanta, GA
    Posts
    34

    Default Re: Creating multiple user logins assigned to multiple groups at one time

    Then it says:
    Verify that your /etc/group, /etc/passwd and /etc/shadow files are updated:
    ***does this mean that typing the following lines of code will automatically update these files?
    Code:
    less /etc/group
    less /etc/passwd
    less /etc/shadow

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    14,767

    Default Re: Creating multiple user logins assigned to multiple groups at one time

    Please, when you do not know exactly what a certain command (like less) is doing, then use
    Code:
    man less
    Then you will see that less only lists a file in a certain way and does not change the file and certainly will not "update" it.

    Same
    Code:
    man 5 passwd
    will explain to you what all the fields in /etc/passwd are for. And when you have no shell defined, the user can not log in because he will have no shell to run. And in Linux it is rather normal to have bash as shell. But you (as system manager) can of course offer them another shell. And the user can himself change the shell, either after login for the moment (exec), or as starter for her/his next login (chsh).

    I do not know the command newusers, thus I can not make any comment on it's functionality. The standard command to add a user is useradd and that command can of course be used in a script that reads a batch of users to add and then do that useradd.

    My advice would be to study several man pages and may be some more documentation about user/group administration before you begin to act as system manager for a rather big group of users.

    Of course, when during that study you encounter questions on details, you can come back here, but it is a bit difficult to explain all the basics here, the more while the docs are available on your system.
    Henk van Velden

  4. #4
    Join Date
    Feb 2011
    Location
    Atlanta, GA
    Posts
    34

    Default Re: Creating multiple user logins assigned to multiple groups at one time

    Thanks. I appreciate your reply on this. I have been going thru the "man" pages, I just hadn't quite gotten that far yet when I made the post, but I did afterwards realize that this was just viewing those files to make sure they had been changed.

    My biggest question was in the initial post, as to whether the script and instructions that I found (and I have been researching this for days) would indeed do what I am trying to do. And whether it would allow me to add that list of users to more than one group, or if I'd have to go in and run a different script to bulk-add them to an additional group.



    As far as acting as system manager for a big group of users, no choice there. Was win2kpro before, but it was no longer supported, and finally when the machine died, it was replaced with a newer refurbished machine with no OS on it yet, and after some discussion, it was decided to try this, as I'd had success with it personally on my own computers.

    I've just not had to add such a large group of users under linux before. On windoze, there are various tools for quickly cloning user accounts, etc. So that's what I've been trying to find here, is a way to either add a bunch of users at once with the same settings for all, or a ready-made tool of some sort that will do this.

    System has been down for a few days now, between the old one dying, and getting this new one set up, and I've been researching this question for days, and not found an adequate answer, and I'm trying to hurry a bit due to the people in the building getting impatient. I've already got the networking and printer sharing and stuff set up. Just need to get all these accounts added and hoping to avoid hours and hours of data entry.

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    14,767

    Default Re: Creating multiple user logins assigned to multiple groups at one time

    I repeat, I can not comment on a script you found somewhere and where you only provide it's name. When you want people to comment on a script found somewhere in the dark on the internet, you better provide it's contents here.
    Henk van Velden

  6. #6
    Join Date
    Feb 2011
    Location
    Atlanta, GA
    Posts
    34

    Default Re: Creating multiple user logins assigned to multiple groups at one time

    Ummmm... I DID provide the entire directions/contents of it in the initial post.
    I'll summarize again below:

    (chmod the batch-user-add.txt file)
    # touch /root/batch-user-add.txt
    # chmod 0600 /root/batch-user-add.txt

    (open the batch-user-add.txt file to edit it)
    # vi /root/batch-user-add.txt

    (add the following into the batch-user-add.txt file)
    Code:
    Unit0106:concorderesident:1201:1001:Unit 106:/home/Unit0106:/bin/bash
    Unit0107:concorderesident:1202:1001:Unit 107:/home/Unit0107:/bin/bash
    Unit0108:concorderesident:1203:1001:Unit 108:/home/Unit0108:/bin/bash
    Unit0109:concorderesident:1204:1001:Unit 109:/home/Unit0109:/bin/bash
    Unit0201:concorderesident:1205:1001:Unit 201:/home/Unit0201:/bin/bash
    Unit0202:concorderesident:1206:1001:Unit 202:/home/Unit0202:/bin/bash
    Unit0203:concorderesident:1207:1001:Unit 203:/home/Unit0203:/bin/bash
    Unit0204:concorderesident:1208:1001:Unit 204:/home/Unit0204:/bin/bash
    Unit0205:concorderesident:1209:1001:Unit 205:/home/Unit0205:/bin/bash
    Unit0206:concorderesident:1210:1001:Unit 206:/home/Unit0206:/bin/bash
    Unit0207:concorderesident:1211:1001:Unit 207:/home/Unit0207:/bin/bash
    Unit0208:concorderesident:1212:1001:Unit 208:/home/Unit0208:/bin/bash
    Unit0209:concorderesident:1213:1001:Unit 209:/home/Unit0209:/bin/bash
    Unit0210:concorderesident:1214:1001:Unit 210:/home/Unit0210:/bin/bash
    Unit0301:concorderesident:1215:1001:Unit 301:/home/Unit0301:/bin/bash
    Unit0302:concorderesident:1216:1001:Unit 302:/home/Unit0302:/bin/bash
    Unit0303:concorderesident:1217:1001:Unit 303:/home/Unit0303:/bin/bash
    Unit0304:concorderesident:1218:1001:Unit 304:/home/Unit0304:/bin/bash
    Unit0305:concorderesident:1219:1001:Unit 305:/home/Unit0305:/bin/bash
    Unit0306:concorderesident:1220:1001:Unit 306:/home/Unit0306:/bin/bash
    (save the file, and then run the linux command newusers)
    # newusers /root/batch-user-add.txt

    I didn't find it somewhere in the dark on the internet. newusers is a linux command. And I am trying to follow the directions between that and the linked man pages of passwd and other related commands, and am trying to find out if it will A) do what I need it to do, and B) if I've got the syntax right.
    newusers(8): update/create new users in batch - Linux man page
    passwd(5): password file - Linux man page


    I don't know how many other ways I can word my questions? I know I'm new to all this, but I HAVE been doing my homework and reading for days now, and trying to ask intelligent questions, only to be put down?

  7. #7
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    14,767

    Default Re: Creating multiple user logins assigned to multiple groups at one time

    Sorry, some misunderstanding. But I do not have the tool newusers (and thus not it's man page) on my standard 11.2 system. Thus my idea was after reading:
    I did some research and found that it should be possible to add them using a script, but there were so many changes whenever a possible script was posted that I had trouble following the message threads to get a coherent final script to use.

    So far, here is what I have found, and I hope this works in Suse 11.3:
    But it doesn't say anything about adding to more than one group? I know if I add thru YAST, it adds to users, and then by default adds to the additional group "video" (is this for them to be able to log in with the gui?)

    However, the script I found shows one user
    that you use some script found somewhere.

    I will read through the man page you provided a link to after my lunch
    Henk van Velden

  8. #8
    Join Date
    Aug 2008
    Location
    Behind the 8 ball
    Posts
    116

    Default Re: Creating multiple user logins assigned to multiple groups at one time

    I've never used the newusers command, so I would just use a custom script to add the users.

    For example
    Code:
    #!/bin/bash
    
    for USERS in $(cat /root/batch-user-add.txt)
    do
      USER=`echo ${USERS} | cut -d ":" -f1`
      PASSWD=`echo ${USERS} | cut -d ":" -f2`
      UID=`echo ${USERS} | cut -d ":" -f3`
      ##Add more fields here...
    
      ##man useradd to learn about all the switches
      useradd ${USER} -p ${PASSWD} -u ${UID}
    done
    You can use the chage command to force a user to change their password

    Code:
    chage -d 0 Unit0106
    Hiatt

  9. #9
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,941
    Blog Entries
    4

    Default Re: Creating multiple user logins assigned to multiple groups at one time

    You should not be modifying passwd, shadow, group files directly. You should call useradd to do the work. Among other things it creates the home directory, puts initial files there and does various checks. It will also flag the account for a password change if wanted.

  10. #10
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    14,767

    Default Re: Creating multiple user logins assigned to multiple groups at one time

    Quote Originally Posted by jthiatt08 View Post
    I've never used the newusers command, so I would just use a custom script to add the users.

    For example
    Code:
    #!/bin/bash
    
    for USERS in $(cat /root/batch-user-add.txt)
    do
      USER=`echo ${USERS} | cut -d ":" -f1`
      PASSWD=`echo ${USERS} | cut -d ":" -f2`
      UID=`echo ${USERS} | cut -d ":" -f3`
      ##Add more fields here...
    
      ##man useradd to learn about all the switches
      useradd ${USER} -p ${PASSWD} -u ${UID}
    done
    You can use the chage command to force a user to change their password

    Code:
    chage -d 0 Unit0106
    Hiatt
    I would replace
    Code:
    USER=`echo ${USERS} | cut -d ":" -f1`
      PASSWD=`echo ${USERS} | cut -d ":" -f2`
      UID=`echo ${USERS} | cut -d ":" -f3`
      ##Add more fields here...
    with
    Code:
    echo "$USERxiS" | IFS=':' read USER PASSWD UID GID INF HOME SHELL
    Or even more radical:
    Code:
    while IFS=':' read USER PASSWD UID GID INF HOME
    do      useradd $USER -p $PASSWD
             # more parameters and more statements
    done </root/batch-user-add.txt
    But those are all niceties.
    Henk van Velden

Page 1 of 6 123 ... LastLast

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
  •