Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
i have many users, suppose userA, userB, userC,userD,userE i want to add them all in a group name USERS in a single command. Thanks...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    63

    how add multiple users in a single group

    i have many users, suppose userA, userB, userC,userD,userE

    i want to add them all in a group name USERS in a single command.

    Thanks

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,100
    Create a script: group_usersA2E.sh
    Code:
    #!/bin/sh
    
    for USER in userA userB userC userD userE; do
      usermod -G USERS $USER
    done

    then do
    sh ./group_usersA2E.sh
    One command, as requested

    Ok, a bit more seriously:
    There is no command to do that.
    So you will need a helper or wrapper script.

  3. #3
    Just Joined!
    Join Date
    Mar 2008
    Posts
    63
    thanks for reply,
    But you suggested command will add all the users in the USERS group if let suppose i want to add only specific users in the USERS group then what i do,

    i think the $USER will add all the users

  4. #4
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,100
    I am a bit confused now, your first post:
    i want to add them all in a group name USERS
    contradicts the second
    But you suggested command will add all the users in the USERS group
    Could you explain again, what the result should look like?

  5. #5
    Just Joined!
    Join Date
    Mar 2008
    Posts
    63
    Ohh sorry you are right
    Actually this is my second question
    suppose i have 15 users and i only want to add 5 users in the particular group

    Thanks in advance

  6. #6
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,100
    Is there any way to distinguish these users?
    A script needs a hint to pick the right users.

    This is an example from /etc/passwd
    Code:
    userA:x:1000:1000:userA Description:/home/userA:/bin/bash
    Do these five users have anything in common?

  7. #7
    Just Joined!
    Join Date
    Mar 2008
    Posts
    63
    emmmm NO. and i think it not possible to fullfill my query

    ok leave it

  8. #8
    Just Joined!
    Join Date
    Nov 2007
    Posts
    44
    you really want to go the script-way? As root you can try,
    Code:
    gpasswd -a <userA> <userB> <userC> ... <GROUP>

  9. #9
    Just Joined!
    Join Date
    Mar 2008
    Posts
    63
    as you told me the below command i am not able to use this command...yes i can use the command in the following maner
    gpasswd -a user1 group1
    but i am not able to add multiple users in a single group in one go, as you told
    gpasswd -a user1 user2 user3 user10 user15 group1

    .......................

    second thing if i delete a user from the /etc/group.. does the user properly delete from the /etc/group via vi /etc/group

  10. #10
    Just Joined!
    Join Date
    Nov 2007
    Posts
    44
    Sorry had not tried the -a option for multiple users. Try
    Code:
    gpasswd -M userA,userB,userC,... <GROUP>
    -M or --members is for multiple users. I tried it for dummy users test1 and test2 on group users and this is what i got.
    Code:
    gpasswd -M test1,test2 users
    cat /etc/group | grep users
    users:x:100:test1,test2
    Did not understand second question properly. You mean manually deleting a user's name from a group is as effective/correct as deleting a user from a group via any command? Yes, it may look crude but it works.

Page 1 of 2 1 2 LastLast

Posting Permissions

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