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

3 Answers 3


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.


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/'

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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