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).
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:
will show all user accounts: both those from
/etc/passwd
and your central user directory.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 code0
) or that you're missing some (exit code3
indicates a database that does not support enumeration and you'll need to use appropriate tools for that specific database...).You can then pipe the output to other programs/scripts for further processing.