LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   user is not listed in the group (https://www.linuxquestions.org/questions/linux-newbie-8/user-is-not-listed-in-the-group-772426/)

newk 11-30-2009 07:13 AM

user is not listed in the group
 
Ubuntu 9.04

groupadd -g 901 sales
usermod -g 901 myuser

The following is the string from the /etc/group file:

sales:x:901:

Where is myuser?

But I have also another question. When I do this for the normal user I can see that added group at least in the output of the group command (and not in the /etc/group file)

But when I do this for sudoer user I can't see an added group even in the output of the group command (logging as that sudoer user).

Thanks.

MensaWater 11-30-2009 07:35 AM

usermod -g change PRIMARY group so the group ID (GID) is specified in /etc/passwd for the user rather than in /etc/group. If you don't want to change PRIMARY but rather add to ADDITIONAL groups you'd use usermod -G instead. It will then leave the GID in /etc/passwd unmodified and show the user in /etc/group associated with the group you selected.

newk 11-30-2009 07:48 AM

But groups after -G have just replaced previous groups but only primary group has remained (and NEW additional secondary groups). How to ADD new groups to the list.

The following is the quote from the Beginning Ubuntu LTS Server Administration From Novice to Professional, Second Edition by Sander van Vugt:

"Group Ownership
When working with group ownership, you should be aware of how group ownership is handled.
By default, the primary group of the user who creates a new file becomes the group
owner of that file. If, however, the user is a member of more than one group, this default setting
can be manipulated. When a user issues the newgrp command, he can change the primary
group setting on a temporary basis. The following steps show what happens next:

1. Log in as some normal user on your computer. Then use the groups command from a
console window to get an overview of all groups that you are currently a member of.
The primary group is listed first. If you haven’t modified anything for this user, it will
have the same name as your user account. Listing 5-4 is an example of this output.

sander@RNA:~$ groups
sander adm dialout cdrom floppy audio dip video plugdev scanner lpadmin admin

2. From the console window, issue the touch newfile command to create a new file
with the name newfile. Then use ls -l newfile to display the ownership information
for newfile. You will see that the primary group is set as the owner of the file (see

sander@RNA:~$ ls –l newfile
-rw-r--r-- 1 sander sander 0 2007-07-28 10:05 newfile

3. Use su to become root. Then use groupadd to create a new group (for example, use
groupadd -g 901 sales to create a group with the name sales and group ID 901). Next,
as root, use usermod -g 901 youruser to make youruser (the user you used in step 1) a
member of that group. After changing this group information, use exit to close the su
session and become the normal user account again.

4. As the normal user, use groups again to get an overview of all groups you are currently
a member of. The new group should appear now, probably as the last group in the list.


5. As the normal user, use newgrp yournewgroup to set the primary group to your new
group on a temporary basis. You can use the groups command to check this; the new
group should now be listed first. You’ll also see that if you create a new file (use touch
somenewfile), the new group will be group owner of the new file. This ensures that all
users who are members of the same group can do the same thing to this file."

MensaWater 11-30-2009 08:15 AM

If you're asking how you can put new groups in /etc/group you do that with the groupadd command.

groupadd -g <GID> <groupname>

e.g.
groupadd -g 700 oracle
Would add group named "oracle" with GID of 700.

You could then use the useradd -G oracle <username> to add the user you want to the group.


From the usermod man page on CentOS 5:

Quote:

-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
A list of supplementary groups which the user is also a member of.
Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option. If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via -a option, which appends user to the current supplementary group list.
Notice the sentence I bolded.

You can usually get lots more information about any UNIX/Linux command by typing "man <command>" where command is the one you're interested in e.g. man groupadd
man usermod

newk 11-30-2009 08:26 AM

Thank you jlightner. But I just did steps from the book (see please my previous edited post, if it doesn't bother you). So what is your opinion about that quotation? I agree with you regarding man pages.


All times are GMT -5. The time now is 08:32 AM.