7

It surprised me, that no search has led me to such a simple question like this one. All I want is to get a list of users and usergroups (whatever the second thing actually is).

I've found many resources about user accounts being created or removed, but it sounds like everyone remembered all the accounts on their system by heart. I guess it's not that way.

So how do I list them, their permissions and how do I list groups?

10

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

5

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.

1
less /etc/passwd | cut -d":" -f1
  • ...and the groups? – Jeff Schaller Feb 21 '18 at 2:19
  • It is actually a useful (although incomplete) answer. I used the more compact but similar cut -d: -f1 /etc/passwd – Kar.ma Feb 22 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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