Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How to list all users and groups on linux?

How to determine all the users on a Linux machine (not only the ones who are logged in)?

I searched and found the following command:

$ cat /etc/passwd | grep "/home" | cut -d: -f1

But my concern is that I could not find root in the output of above command. Also when I try who command I get the same response when I am logged in a root and as a normal user. Please help!

share|improve this question

marked as duplicate by Zoredache, Chopper3 Sep 11 '11 at 19:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

You've specified additional information for your question in the comments. Please update your question to include these points. – Dana the Sane Sep 11 '11 at 19:18

your command wont find root because root's home is /root not /home/[user] also, it wont show remote network accounts.

a better command is getent passwd | cut -d ":" -f1.

share|improve this answer
But what about the who command? When I am logged into as sam user then it shows output sam. When I am logged into as root then also it shows sam. – iSumitG Sep 11 '11 at 18:28
refer to "man who" for more info. Shows logged in users, not all users. re your query, did you log in as sam and then run su/sudo, or did you go directly as root from login prompt. Also if you are logged in as sam else where (like anouther window) itll show up – Sirex Sep 11 '11 at 18:33
getent is the right way to check the user database. – Pablo Martinez Sep 11 '11 at 18:40
Sirex: I want to login as a account which is having /bin/false shell. How can I do it? Is there any way to do it? – iSumitG Sep 11 '11 at 18:45
this is nearly always a bad idea. However you can do it by changing the shell to be /bin/bash and setting a password on the account. In all seriousness though, the need to do this is a good indication of a case of "you're doing it wrong" – Sirex Sep 11 '11 at 20:42

Take the search (grep) out and cut at the first semi-colon: cat /etc/passwd | cut -d: -f1

share|improve this answer
It lists many many things like: operator, games, gopher, ftp, dbus, vcsa. All of them are users? – iSumitG Sep 11 '11 at 18:14
Yes, they are users. Many are created by the OS/applications on install. Have a look at cat /etc/passwd – xofer Sep 11 '11 at 18:18
yes, but unless they have a shell in them like /bin/bash they cant log in. typically the shell is set to /bin/false for these "service accounts". – Sirex Sep 11 '11 at 18:28
ok, to exclude /bin/false, use cat /etc/passwd | grep -v "/bin/false" | cut -d: -f1 To only include /bin/bash use cat /etc/passwd | grep "/bin/bash" | cut -d: -f1 – xofer Sep 11 '11 at 18:36
Login as root and su - <user> -s /bin/bash. – quanta Sep 11 '11 at 18:41

Because $HOME folder for root is /root, not in /home.

To list all the 'real' users have shell (assumming is /bin/bash), you can use:

grep "/bin/bash" /etc/passwd | cut -d: -f1
share|improve this answer
Ohh..ok. But what about the who command? When I am logged into as sam user then it shows sam. When I am logged into as root then also it shows sam. – iSumitG Sep 11 '11 at 18:15
Please give us the output of who and egrep 'root|sam' /etc/passwd? – quanta Sep 11 '11 at 18:23
Output of egrep: root:x:0:0:root:/root:/bin/bash operator:x:11:0:operator:/root:/sbin/nologin – iSumitG Sep 11 '11 at 18:24
Output of 'who': sam pts/0 Sep 11 23:01 <ip address> – iSumitG Sep 11 '11 at 18:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.