I know I have existing groups and users but I'm not sure about their association. Is there an shell command I can use to list all users or all groups and a command to list all groups/users for a specified user/group?
So something like showusers
would list all users, and showgroups -u thisuser
would show all the groups that have thisuser
in it.
All users:
All groups:
All groups with a specific user:
List users and their groups:
List groups and their users:
If you dont care about remote users such as LDAP or NIS, to list users and their associated groups in a simple way:
Output;
List all users
Or
While cat /etc/passwd shows all users (and a bunch of other stuff), cut -d ':' -f 1 is a simple way to split each line with ':' as a delimiter and extract just the first field (users). Pretty much the same as awk version.
List all groups
Or
Guess what, very simmilar to listing users. Just parse /etc/group instead.
Another interesting way, maybe closer to what OP wanted, is compgen. Not sure about compatibility issues though.
Use
getent passwd{1000..60000}
to list only manually added users. See: https://linuxize.com/post/how-to-list-users-in-linux/for debian
Like this:
Use this command to get all the group and users in that particular group.