Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm a student in a university and I can finger and id all users (students etc) through SSH.

Here is the id command

e147200@beluga:~$ id e201634
uid=22678(e201634) gid=3561(stat_bs) groups=3561(stat_bs)

Here I can see that the student with id e201634 is agraduate student (bs) at Statistics department (stat).

Is there a way to download this gid (or groups) table?

3561 stat_bs
3562 stat_ms
3611 chem_bs
3687 biol_bs
...
share|improve this question

3 Answers 3

up vote 5 down vote accepted

If the server has getent, and allows users to view such information, you may be able to use getent group stat_bs. This will give you a list of users, separated by commas.

If getent group is disallowed, you still might be able to read the passwd database with getent passwd. You can then correlate the GID (the fourth column) with the desired group.

share|improve this answer
    
or perhaps getent group stat_bs to see all the members of the stat_bs group –  steeldriver May 17 at 20:02
    
    
Some are missing such as arme_spc and id_spc –  ilhan May 17 at 20:19
    
This one works gist.github.com/ilhanyumer/9d5b6fc15de683aa2142 –  ilhan May 17 at 20:33

reading the /etc/group file as @Chirag64 suggested will only yield the system-local user groups.

You might want to use getent group (or getent passwd for the user list) instead. The output is formatted in the same way as the passwd or group file (and therefore you can have a look at the respective manpages of group and passwd for help on the file format)

To get a list of group names and their GIDs, try the following

getent group|cut -d: -f1,3

And if you want the same format as in your example, sed the output:

getent group|cut -d: -f1,3|sed -e 's/\(^[^:]*\):\(.*\)/\2 \1/'
share|improve this answer

You can just read the /etc/group file using cat or less which should contain the names and GIDs of each group with the list of users in them.

If you wish to get the UIDs of each user, you can get them from the /etc/passwd file.

Edit: As Chris Down and mreithub mentioned, this is less likely to work in a university server setup since they would only show the system's local user groups and most systems are likely to have logins using NIS or LDAP or some other means.

share|improve this answer
2  
This is unlikely to work, most universities propagate logins using NIS/LDAP/etc, not by hardcoding them. –  Chris Down May 17 at 19:58
    
@Chirag64, unfortunately there is something else gist.github.com/ilhanyumer/94c604f30310bfd3572e –  ilhan May 17 at 20:00
    
@ChrisDown: you're right. I've added clarification in my answer. Your solution seems to solve the problem in those situations. –  Chirag64 May 17 at 20:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.