How to View Available Users
Whether it was created as an account for a real human or associated with a specific service or system function, every user on a Linux system is defined in the file /etc/passwd.
The file /etc/passwd contains information about the users on the system. Each line describes a separate user.
Take a look using the less command, so that you can scroll through the whole file:
less /etc/passwd
Outputroot:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
. . .
Each line is divided into fields. These fields are separated by the colon (:) character.
The only field you need right now is the first one. Each is an individual username. When you are done with less, press q to quit.
You can get this list by splitting the entire "/etc/passwd" file on colon delimiters with the cut command ( -d :):
cut -d : -f 1 /etc/passwd
Outputroot
daemon
bin
sys
sync
games
. . .
You probably recognize root as the administrative user. Toward the end, you may see the user you are logged in as.
In between, you will probably see a number of other users whose purpose looks at least somewhat clear. For example, www-data is configured as the owner of web server processes.
This is done to separate functional privileges. That way, if an account is compromised or misused, the impact will be isolated.
You can learn more about the /etc/passwd fields in this tutorial.
Viewing Available Groups
To explore system groups, the relevant file is /etc/group.
You can use less again to view this file:
less /etc/group
Outputroot:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
. . .
You may notice that many of the group names mirror the users you discovered on your system. This is part of a configuration scheme called user private groups or UPG.
User private groups create a private group for each user and set that group as the primary group. The umask is then changed from 022 to 002 .
This allows more flexibility in shared directories by setting a flag called setgid, which gives files inside the directory the same group ownership as the directory itself.
Once again, you can parse the information in the /etc/group file using the cut command:
cut -d : -f 1 /etc/group
Outputroot
daemon
bin
sys
adm
tty
disk
. . .
The output will be a list of every group on the system, one per line.
How to Find Which Users Are Logged In
Often, it will be more useful to find out which users are active on your system.
The w command is a simple way to list all currently logged-in users, how long they have been logged in, and which commands they are currently running:
w
Output19:37:15 up 5:48, 2 users, load average: 0.33, 0.10, 0.07
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 rrcs-72-43-115-1 19:15 38.00s 0.33s 0.33s -bash
demoer pts/1 rrcs-72-43-115-1 19:37 0.00s 0.47s 0.00s w
The first line contains the system uptime information. The lines below describe who is logged in.
An alternative that provides similar information is who:
who
Outputroot pts/0 2013-09-05 19:15 (rrcs-72-43-115-186.nyc.bizim.com)
demoer pts/1 2013-09-05 19:37 (rrcs-72-43-115-186.nyc.bizim.com)