?
Solved

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

Posted on 2003-03-25
5
Medium Priority
?
230 Views
Last Modified: 2010-04-20
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!
0
Comment
Question by:lakeryu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Accepted Solution

by:
edey earned 320 total points
ID: 8208673
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
 

Author Comment

by:lakeryu
ID: 8208918
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
 
LVL 2

Expert Comment

by:linxit
ID: 8209152
All the system users/groups have uid/gid < 100, so it should be easy programmatically to discard them.
0
 

Expert Comment

by:CleanupPing
ID: 9087614
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
 
LVL 2

Expert Comment

by:TheWeakestLink
ID: 9289757
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

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question