This is a discussion on Getting the list of members in a group. within the Linux Operating System forums, part of the Unix Operating Systems category; --> This appears to be a simple question, but I have never gotten round to find out due to webmin. ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| On Jun 20, 6:59 am, voipfc <voi...@googlemail.com> wrote: > This appears to be a simple question, but I have never gotten round to > find out due to webmin. > > How do you list the members of group from the command line? The simplest way would be to cat /etc/group and look at the fourth field A bit more complex would be grep 'groupname' /etc/group and look at the fourth field And, you could awk -F : '$1 ~ /groupname/ { print $4}' /etc/group and look at the output |
| |||
| On 2007-06-20, Lew Pitcher <lpitcher@teksavvy.com> wrote: > On Jun 20, 6:59 am, voipfc <voi...@googlemail.com> wrote: > The simplest way would be to > cat /etc/group > and look at the fourth field All those have a problem: they don't give you all the members for a group. If I do this on my system: # id uid=1000(davide) gid=100(users) groups=100(users),11(floppy),17(audio),18(video),1 9(cdrom) # grep users /etc/group users::100: So I'm member of the group 'users' but I do not appear in the group file associated to that group. Davide -- Microsoft seems to have gotten a lot of mileage out of the C2 rating for NT with no network connection. I wonder if a B3 rating for Linux with no power cord might be of value. |
| |||
| On Jun 20, 8:21 am, Davide Bianchi <davideyeahs...@onlyforfun.net> wrote: > On 2007-06-20, Lew Pitcher <lpitc...@teksavvy.com> wrote: > > > On Jun 20, 6:59 am, voipfc <voi...@googlemail.com> wrote: > > The simplest way would be to > > cat /etc/group > > and look at the fourth field > > All those have a problem: they don't give you all the members for a > group. > > If I do this on my system: > > # id > uid=1000(davide) gid=100(users) > groups=100(users),11(floppy),17(audio),18(video),1 9(cdrom) > > # grep users /etc/group > users::100: > > So I'm member of the group 'users' but I do not appear in the group file > associated to that group. Actually, your results reflect a (common) problem with setup. It appears that the "primary group" value from the various users recorded in your /etc/password have not been carried over to your /etc/group file. If you are in this situation, then the process of obtaining a complete listing for a group becomes a bit more complex. I don't think that there is a specific tool that will answer your question in this case, but a shell script could be crafted to do what you want. |
| |||
| Lew Pitcher wrote: > On Jun 20, 8:21 am, Davide Bianchi <davideyeahs...@onlyforfun.net> > wrote: >> On 2007-06-20, Lew Pitcher <lpitc...@teksavvy.com> wrote: >> >>> On Jun 20, 6:59 am, voipfc <voi...@googlemail.com> wrote: >>> The simplest way would be to >>> cat /etc/group >>> and look at the fourth field >> All those have a problem: they don't give you all the members for a >> group. >> >> If I do this on my system: >> >> # id >> uid=1000(davide) gid=100(users) >> groups=100(users),11(floppy),17(audio),18(video),1 9(cdrom) >> >> # grep users /etc/group >> users::100: >> >> So I'm member of the group 'users' but I do not appear in the group file >> associated to that group. > > Actually, your results reflect a (common) problem with setup. It > appears that the "primary group" value from the various users recorded > in your /etc/password have not been carried over to your /etc/group > file. This is NOT a problem. It is designed this way. To get a view into all groups and "membership" ... you'll have to look at both /etc/passwd (where just a gid for the primary is found) and /etc/group (where you'll find gid to name mappings and supplemental group membership). > > If you are in this situation, then the process of obtaining a complete > listing for a group becomes a bit more complex. I don't think that > there is a specific tool that will answer your question in this case, > but a shell script could be crafted to do what you want. > For example (off the top of my head)... No warranties... #!/bin/sh # # Sort /etc/group and /etc/passwd ALPHABETICALLY by gid # sort -t: +2 /etc/group >/tmp/group-sorted.out sort -t: +3 /etc/passwd >/tmp/passwd-sorted.out # # Join on the gid field and cut out just the username and the gid # join -t: -1 4 -2 3 /tmp/passwd.sorted /tmp/group.sorted | cut -d: -f2,8 >/tmp/primary-group.out # # Read the username and primary group, find supplemental groups for # each username and do final output. # while IFS=: read username pgrp;do # # Grep supplemental groups, but remove the primary # group if found again (that is non standard btw) # sgrps=`grep "[,]*${username}[,]*" /etc/group | cut -d: -f1 | grep -v "^${pgrp}\$"` # # Separate groups with commas, remove trailing # comma. # allgrps=`echo -e "$pgrp\n$sgrps\c" | tr '\012' ',' | sed 's/,$//'` # # Output the result # echo "$username:$allgrps" done </tmp/primary-group.out |
| ||||
| On 2007-06-20, voipfc <voipfc@googlemail.com> wrote: > > How do you list the members of group from the command line? Again, I'm surprised not to see this suggestion: getent group This does suffer from the same drawback as looking solely at /etc/group, in that it won't tell you where a userid has his primary gid listed in /etc/passwd but not in /etc/group. But it has the advantage that it will list all available groups, if your box is an NIS or LDAP (pam_ldap or nss_ldap) client. --keith -- kkeller-usenet@wombat.san-francisco.ca.us (try just my userid to email me) AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt see X- headers for PGP signature information |