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...
- 12-15-2009 #1Just 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
- 12-15-2009 #2
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.
- 12-16-2009 #3Just 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
- 12-16-2009 #4
I am a bit confused now, your first post:
contradicts the secondi want to add them all in a group name USERS
Could you explain again, what the result should look like?But you suggested command will add all the users in the USERS group
- 12-16-2009 #5Just 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
- 12-16-2009 #6
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
Do these five users have anything in common?Code:userA:x:1000:1000:userA Description:/home/userA:/bin/bash
- 12-16-2009 #7Just Joined!
- Join Date
- Mar 2008
- Posts
- 63
emmmm NO. and i think it not possible to fullfill my query

ok leave it
- 12-16-2009 #8Just 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>
- 12-16-2009 #9Just 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
- 12-16-2009 #10Just Joined!
- Join Date
- Nov 2007
- Posts
- 44
Sorry had not tried the -a option for multiple users. Try
-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 userA,userB,userC,... <GROUP>
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.Code:gpasswd -M test1,test2 users cat /etc/group | grep users users:x:100:test1,test2


Reply With Quote