LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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



Reply
 
Search this Thread
Old 01-31-2006, 04:26 PM   #1
krystian
LQ Newbie
 
Registered: Jun 2003
Posts: 8

Rep: Reputation: 0
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)
  1. The command: "users" only returns a list of all users logged in currently.
  2. 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.
 
Old 01-31-2006, 04:29 PM   #2
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
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...
 
Old 01-31-2006, 04:36 PM   #3
krystian
LQ Newbie
 
Registered: Jun 2003
Posts: 8

Original Poster
Rep: Reputation: 0
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
 
Old 01-31-2006, 04:45 PM   #4
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
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 04:52 PM.
 
Old 02-01-2006, 01:59 AM   #5
krystian
LQ Newbie
 
Registered: Jun 2003
Posts: 8

Original Poster
Rep: Reputation: 0
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.
 
Old 02-01-2006, 02:27 AM   #6
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,164

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
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).
 
Old 02-01-2006, 11:08 AM   #7
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
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 11:11 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HowTo list all users in system ALInux Linux - Newbie 22 11-23-2005 04:50 AM
command to list all users of the system?? simi_544 Linux - Networking 9 09-29-2005 04:00 AM
Is it possible to use system() and get the return value from the system call newguy21 Programming 1 08-11-2004 02:37 PM
How to use return values from system functions? kpachopoulos Programming 2 07-30-2004 04:09 AM
How to get list of system users from command line? tictocdoc Linux - General 3 03-12-2004 04:06 PM


All times are GMT -5. The time now is 08:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration