how can I get the all users and groups registered in the system ?

I want to get the info of all  users and groups who is registerd in the Linux system. How can I realize it through language Python.
for example:in the system there are two groups: groupA and groupB , four users user1, user2, user3, user4, user1 and user2 are in groupA, user3 and user4 are in groupB.
I want: get userList user1,user2,user3,user4 and their group info.
        get groupList groupA and groupB.

that's all!
How can I do? wait for your answer. thanks!
lakeryuAsked:
Who is Participating?
 
edeyConnect With a Mentor Commented:
I don't know python very well but, in theory, all the users should be in /etc/passwd (try a cut -d':' -f1 /etc/passwd for a list of just user names) and the groups a user is in should be listed in /etc/group

I grabbed this snippet from the group man file:

/etc/group  is  an  ASCII  file which defines the groups to which users belong.  There is one entry per line, and each line has the format:
   group_name:passwd:GID:user_list

so it looks like, for this question anyway, the /etc/group file is already a list as you wanted

GL
Mike
0
 
lakeryuAuthor Commented:
thanks a lot! through your method it can get the users,
but I do't want to get the users and groups which is created when install the system. such as "bin", "daemon" "mail" and so on. can you solve it?

wait for your answer!
best regards
0
 
linxitCommented:
All the system users/groups have uid/gid < 100, so it should be easy programmatically to discard them.
0
 
CleanupPingCommented:
lakeryu:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
TheWeakestLinkCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept comments from edey as answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheWeakestLink
EE Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.