3

I am in the process of migrating to a new server and I am having a number of issues due to user accounts not being present (for example nginx seems to be running under nginx user on the new system www-data on the old system).

Is there an easy way to get all the user / group account information. (Ideally I would like to script the creation of new accounts with Ansible if that makes any difference).

wobbily_col
  • 653
  • 2
  • 7
  • 14

2 Answers2

8

How to list all users and groups depends on how authentication is configured.

The most basic are the /etc/passwd and /etc/group files used for local authentication.

Using those files is insufficient to get a complete listing when user/group data is stored centrally, for instance in LDAP, NIS, Hesiod, etc.

Central authentication is usually configured in addition to the /etc/passwd and /etc/group files to allow the system to be booted and viable in single user mode by means of the Name Service Switch configuration file /etc/nsswitch.conf

If configured with NSS:

getent passwd 

will show all user accounts: both those from /etc/passwd and your central user directory.

getent group 

will show all groups.

By monitoring the exit status of the getent command you will also know if you did indeed list all users/groups (exit code 0) or that you're missing some (exit code 3 indicates a database that does not support enumeration and you'll need to use appropriate tools for that specific database...).

HBruijn
  • 77,029
  • 24
  • 135
  • 201
  • 1
    To further complicate matters `sssd.conf` defaults to `enumerate: FALSE` and still causes `getent` to return 0. – 84104 Apr 22 '16 at 22:34
3
cat /etc/passwd  # show all users
cat /etc/group   # show all groups

You can then pipe the output to other programs/scripts for further processing.

user121391
  • 2,502
  • 13
  • 31