LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-19-2004, 10:48 PM   #1
eam
Member
 
Registered: Nov 2003
Location: USA
Distribution: Slackware
Posts: 67

Rep: Reputation: 15
List all users


Is there a command to list all users? I tried google but all I found was how to list users who are logged in.
 
Old 02-20-2004, 12:05 AM   #2
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 388

Rep: Reputation: 52
This should work:

cut -d: -f1 /etc/passwd

Lyle
 
Old 05-11-2005, 12:46 AM   #3
sateesh
LQ Newbie
 
Registered: May 2005
Location: Hyderabad, India
Distribution: Fedora and SuSE(currently)
Posts: 2

Rep: Reputation: 0
Bash command to get list of users

I executed the command but that gave this....
__________________________________________
chosa06-l:~ # cut -d: -f1 /etc/passwd
root
bin
daemon
lp
mail
news
uucp
games
man
at
wwwrun
ftp
postfix
mysql
sshd
ntp
nobody
adminsupport
nmc
_________________________________________

But in the list only "root" and "nmc" are users.
How to get the correct user list?
Please help.
 
Old 05-11-2005, 03:05 AM   #4
Tanc
Member
 
Registered: Sep 2003
Location: France
Distribution: Debian etch
Posts: 99

Rep: Reputation: 15
cat /etc/passwd | cut -d":" -f1

Try webmin if you have to manage users.
 
Old 05-11-2005, 04:57 AM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
By convention, the uid of regular users is within a certain range. On Mandrake and Red Hat, the normal user range starts at 500, while on SuSE the user range starts at 1000. This allows you to filter out the system users. I don't know what convention that Slackware uses. Also, on a Unix/Linux system with many users, the UIDs are grouped by the function of the user also. This is done to make administrating the system easier. For example, you might have faculty between 1200-1399. You may have administrators in the range 1000-1999.

Getting back to your problem, you need to either also look at the third field of the /etc/passwd file for the uid number or use the "id" command.

You may find it easier to come up with an awk script that returns a list of regular users. Then use the result in a loop to do whatever it is you want to do in the script.

In your case, with just one regular user ( root is a super-user ) this may be mostly a learning exercise.
 
Old 05-12-2005, 06:09 AM   #6
sateesh
LQ Newbie
 
Registered: May 2005
Location: Hyderabad, India
Distribution: Fedora and SuSE(currently)
Posts: 2

Rep: Reputation: 0
Hello Mr.jschiwal,
Thank you. Still I am left with 1 doubt. In the listing from uid=0 to uid=503(regular user), what are bin, daemon,...ftp, ntp, mysql and adminsupport?. Are they also users?.
You told that in SuSE the use4r range starts from 1000. But in my SuSE 9.0 system by default the user range started from 501 onwards (like in Redhat Linux). What is your explanation for this?.
I tried the following according to ur suggestion.
______________________________________________
chosa06-l:/usr/src/linux # cut -d: -f3 /etc/passwd >f1
chosa06-l:/usr/src/linux # cut -d: -f1 /etc/passwd >f2
chosa06-l:/usr/src/linux # paste f1 f2
0 root
1 bin
2 daemon
4 lp
8 mail
9 news
10 uucp
12 games
13 man
25 at
30 wwwrun
40 ftp
51 postfix
60 mysql
71 sshd
74 ntp
65534 nobody
500 adminsupport
501 nmc
502 sateesh
503 monu
_______________________________________________________________________
Hello Mr.Tanc,
What is webmin?. How to invoke that?.
Thanks in advnace.
Bye.
 
Old 05-13-2005, 08:35 PM   #7
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
I had thought that I had saved an earlier response yesterday. Anyway, whenever you run a program, the running code has associated with it a UID and an EUID ( effective user id ). Certain services that run in the background are started by root, but very quickly will degrade their permissions to that of a system user setup for that purpose. This if for security reasons. Often the service will run in a chrooted jail, which means that the root is changed to a directory with it's own system file hierarchy, but stripped to the bone. Only what is needed to run the service is present, and a shell option reduces the commands that can be used. Even 'cd' doesn't work. That way if a hacker can cause the service to crash, there is another obsticle to overcome, breaking out of the jail.

I was reading parts of the bash manual on arrays and one example read both the uid and uname from /etc/password. I changed it a little here, I thought it might be useful for you.

user_id= ( $( cut -f 1,3 -d: /etc/passwd ) )

Now the variable user_id contains an array of "uname:uid" strings.

You can handle one of them like this:
echo ${user_id[1]}
You can list the entire array like this:
echo ${user_id[@]}

Suppose you want to know how many elements are in user_id. No problem: echo ${#user_id[@]}
So it would be easy to iterate through each element knowing the number of elements.
Code:
NORMALUSERSTART=500
numentries=${#user_id[@]}
for (( index=0; index<numentries; index++ )); do
    if (( ${user_id[index]#*:} >= $NORMALUSERSTART )) ; then echo ${user_id[index]%*:}
fi
done
This still will list the nobody user, so you may want to extend the test if that isn't acceptable, or decrement $numentries before the loop.

Last edited by jschiwal; 05-13-2005 at 08:38 PM.
 
Old 05-15-2005, 11:55 PM   #8
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
You could use:
sed -n '/^UID_MIN/s/GID_MIN[ \t]*\([[:digit:]][[:digit:]]*\).*$/\1/p' /etc/login.defs
sed -n '/^UID_MAX/s/GID_MIN[ \t]*\([[:digit:]][[:digit:]]*\).*$/\1/p' /etc/login.defs
to extract the range of UIDs on any system that uses the shadow suite.
 
  


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 Off
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 24 02-12-2014 10:43 PM
DISCUSSION: How to list all your USERs.. amitsharma_26 LinuxAnswers Discussion 12 10-16-2012 12:48 AM
list out the users. bruse Linux - Newbie 2 07-19-2005 08:46 AM
Get a list of linux users xedios Linux - Software 4 05-07-2004 06:31 PM
how can i see list of logged on users? doublefailure Linux - General 6 09-10-2002 08:11 PM


All times are GMT -5. The time now is 02:48 AM.

Main Menu
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