How to add user in a group?
Hi,
I have four users in my red hat linux 9. I want that all these four users should add in a group i.e "Marketing".please guide me that using terminal which command may i write so that the users should added in the group. Note:- I does't want to use GUI interface to do it. thanks in advance, garden |
Try this:
Quote:
|
Code:
for user in john bill mary jane |
thanks for the prompt reply. Well the command works fine. Now a question rises that how can I see all four users in "Marketing " Group. Is there anyway command to check it ?
|
Quote:
Quote:
|
You may want to use
Code:
egrep '^Marketing:' /etc/group -- Dan |
thanks a lot all of you for guiding me. Well about users and groups in linux and the files related to it, kindly refer me any site in which I may study it in more detail.
Again thanks garden |
well the command
#cat /etc/group| grep Martketing and egrep '^Marketing:' /etc/group provide same output.So what is the difference in both these and in which situation I may use egrep or cat command. Iam sure there should be a minor difference. |
Man pages will tell you.
Code:
man grep |
Basically grep and egrep is same command, look into the man page for more information.
#man grep |
Quote:
Your example would match more than "Marketing" (e.g. "Marketing2"), that could cause problems when used in scripts. |
Nothing like allowing the OP to answer his/her own question, eh? Your answer isn't quite right either.
from the man page: Quote:
|
Quote:
Yes, you're right. Let's get it entirely right: Code:
/bin/grep '^Marketing:' /usr/group |
If you're really using red hat linux 9 (codename Shrike) http://en.wikipedia.org/wiki/Red_Hat_Linux, it hasn't been updated, inc security in years. Do yourself (& us ) a favour an get something current eg http://en.wikipedia.org/wiki/CentOS
|
Quote:
|
Wow. This was an interesting and unexpected first experience of this forum.
So, the command has been corrected as 'egrep' was deprecated according to the man page. Let's correct the rationale as well: Quote:
|
Quote:
|
Quote:
Code:
man usermod |
Quote:
This was because I was adding ':username' to the end of the scanner line in /etc/group. It should have been ',username'. This is only if there is another name(s) on the end of the line, the first name is indeed seperated by a : . I was, moderately, complaining about being buggered up in this way. My point was it is difficult to work out which groups the user should belong to given that all this information has been destroyed. I was warning people who read this post not to use the idiotic usermod -G command. So to be bloody idiotic: I am in the right and you are in the wrong. |
Not that hard. Could have been solved with a simple google search:
Code:
usermod -a -G group_name user_name |
Quote:
|
Disagree
Quote:
See 2nd sentence.... |
Quote:
|
Quote:
|
Quote:
|
Quote:
|
Quote:
Hi, You could have also created the users with the group reference in one commandline. useradd -g <USER_GROUP> -d <USER_HOME> -c <Some Description> <USERNAME> This command will only work if the USER_GROUP already exists. Command to create user group : groupadd <USER_GROUP> To answer to your last question, use can use either the 'id' command coupled with the username or grep on the group file as shown. eg: grep ^<USER_GROUP> /etc/group eg: id tom You would need to execute 'id' command for each user. |
All times are GMT -5. The time now is 01:42 AM. |