Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-31-2006, 03:26 PM
|
#1
|
|
LQ Newbie
Registered: Jun 2003
Posts: 8
Rep:
|
Return a list of all users in the system
Hello,
Is there shell command which returns the list of all users in the system? (its expected this is to be run as user: root)
- The command: "users" only returns a list of all users logged in currently.
- If I view /etc/group I can see which users are assigned to what groups, but I can't see the list of all users within the system.
My Thoughts:
I think every user in my system has an entry in /etc/passwd.
- However, services have entries too. ex: sshd is a service. Is sshd also a "user", then?
Thanks,
Krystian.
|
|
|
|
01-31-2006, 03:29 PM
|
#2
|
|
Guru
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092
|
If you just want "real" users, one method that works pretty good is ls /home. Of course, some of the directories there are services like ftp...
|
|
|
|
01-31-2006, 03:36 PM
|
#3
|
|
LQ Newbie
Registered: Jun 2003
Posts: 8
Original Poster
Rep:
|
Quote:
|
Originally Posted by pljvaldez
If you just want "real" users, one method that works pretty good is ls /home. Of course, some of the directories there are services like ftp...
|
Problem with that is if root added users as so:
adduser -d /not-in-home
|
|
|
|
01-31-2006, 03:45 PM
|
#4
|
|
Guru
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092
|
Try this: awk -F: '{ if ($3 > 99 && $3 < 100000) { print $1 " " $3 }}' /etc/passwd
This script basically is only printing usernames ($1) and GID's ($3) with a GID of greater than 99. You might try playing with the number 99 and 100000 to see if there's a range that works for you to get rid of all the services stuff. Mine is actually more like 999 and 2000.
Once you've got that trimmed down how you like it, you can delete the " " $3 in the print command to only get usernames.
You can even run this as a regular user.
Last edited by pljvaldez; 01-31-2006 at 03:52 PM.
|
|
|
|
02-01-2006, 12:59 AM
|
#5
|
|
LQ Newbie
Registered: Jun 2003
Posts: 8
Original Poster
Rep:
|
Quote:
|
Originally Posted by pljvaldez
Try this:...
|
Hey, that's awesome. I guess there is no discrete way to cleanly disect services from users.
I like the oneliner. Though it doesn't include root with it's given parameters, it's a bump in the right direction.
I was hoping there was some shell command I overlooked that returned the information I was looking for.
|
|
|
|
02-01-2006, 01:27 AM
|
#6
|
|
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 3,816
Rep: 
|
Most services such as the sshd also have a user account associated with them so that they don't have to run as root (this is a good thing, security wise). You could always check for a valid shell (bash, csh, or the like).
|
|
|
|
02-01-2006, 10:08 AM
|
#7
|
|
Guru
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092
|
Actually, you can include root if you change $3 > 99 to $3 >= 0 because root's uid is 0. Of course, then you get all the system services too, like daemon, bin, sys, sync, man, lp, etc...
Hmmm actually, you can do this to include root:
awk -F: '{ if ($3 = 0 || ($3 > 99 && $3 < 100000)) { print $1 " " $3 }}' /etc/passwd
Last edited by pljvaldez; 02-01-2006 at 10:11 AM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:57 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|