Listing users and usergroups in Raspbian

You can also query a system's users, groups, etc. using the getent command.

Examples

users

$ getent passwd | head -5
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

groups

$ getent group | head -5
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:

The advantage of using getent over just looking at the /etc/passwd and /etc/group files is that getent will query the system using the system's , NSS - Name Service Switch, which defines how "databases" such as these should be handled on a given system.

NSS

The NSS on most Linux systems is controlled through the file /etc/nsswitch.conf. This file defines the "databases" and then how they should be resolved.

Example In the below you can see that the "database" passwd and group should be provied by files, but it could be provided by LDAP, NIS, or any number of other methods.

# /etc/nsswitch.conf

# Example:
#passwd:    db files nisplus nis
#shadow:    db files nisplus nis
#group:     db files nisplus nis

passwd:     files
shadow:     files
group:      files
#initgroups: files

Other databases

Passwords and groups are just 2, there are many databases that are accessible via getent. Take a look at the getent man page for a full list.

You can also get the list from getent's usage page.

$ getent --help
...
Supported databases:
ahosts ahostsv4 ahostsv6 aliases ethers group gshadow hosts initgroups
netgroup networks passwd protocols rpc services shadow
...

References

  • Name Service Switch

There may be more user-friendly ways to display it but all the information is in these two files. For a complete list of user accounts, one account per line:

less /etc/passwd

For a complete list of groups, one group per line:

less /etc/group

See man 5 passwd and man 5 group for details on what all the fields mean.

On the other hand, if your Raspbian has been custom-configured by skilled administrators for the purpose of sharing user and group account information among machines network-wide, then what I have written above is not adequate and you should follow @slm's well-written advice.

Tags:

Debian

Users