LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 02-28-2007, 02:39 PM   #1
cucolin@
Member
 
Registered: Nov 2003
Location: USA
Distribution: Ubuntu, CentOS, RedHat
Posts: 416

Rep: Reputation: 31
Question command to view list of ALL users and/or group


I know if I'm root I can go the the /home folder and see the users there. But I was looking for a command that would list the users/groups in my system even if they are not logged in. I saw a few scripts using awk in order to retrieve the users list from /etc/passwd, but I did not find a command for for just displaying users NOT system users, not sure if it exists.

Thanks
 
Old 02-28-2007, 02:50 PM   #2
iamnothere
Member
 
Registered: Feb 2007
Location: UK
Distribution: Slamd 64, Slackware
Posts: 46

Rep: Reputation: 16
User home directories exist whether they are logged in or not, so what's wrong with 'ls /home' ?

As for filtering /etc/passwd, how about

grep '/home/.*[^:]$' /etc/passwd | cut -f1 -d:

i.e. print all lines that contain '/home' and do not end with ':' (i.e. have a shell field), then print the first field of each line.
 
Old 02-28-2007, 02:55 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You could do that be looking at the UID numbers of the users. However, the ranges used for different distros may be different and you will need to find where that is set, in case it was changed.

On Mandrake, user IDs start with 500. On SuSE, they start with 1000. The kernel doesn't care whether a user is a system user or a regular user. You also need to look at the UIDs used for UIDs of users who exist so they can access samba shares but who don't actually have home directories.

You could also take the users in /etc/passwd and check if their password field indicates a password, or if they have a home directory field entry. A system user may have a home directory entry to function as a working directory. A samba user may have a password entry but not a home directory entry.

Also a user could have a remote home directory or have a home directory which doesn't match their user name.

The best way is to filter users by the UID numbers and make sure that you maintain the system so that regular users are within the regular user range. If you have a GUI inteface for adding or changing users values, it probably sorts out system users the same way.
 
Old 02-28-2007, 03:10 PM   #4
cucolin@
Member
 
Registered: Nov 2003
Location: USA
Distribution: Ubuntu, CentOS, RedHat
Posts: 416

Original Poster
Rep: Reputation: 31
iamnothere I tried your command and got this:

syslog
klog
cupsys
xrgm
ntp
lab3
pc3
sambauser
test

As you can see its listing users such as ntp, cupssys, klog and syslog that I did not create. As jschiwal wrote there are users without a /home directory and they appear using that command. So, users that I created will always be at the /home dir? Thanks for the help...
 
  


Reply



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
What is the command to list users? neo_in_matrix Linux - Newbie 27 11-29-2017 06:09 AM
view list of created users only ALInux Linux - General 5 11-10-2005 01:28 PM
users list in /etc/group Milosevic Slackware 6 11-10-2005 11:30 AM
Way to easily view a list of users that have been added Aij Linux - General 1 09-10-2003 12:03 AM
Cannot view list of users at this time. Wolverine Linux - Networking 6 10-20-2001 07:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:04 PM.

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
Open Source Consulting | Domain Registration