Issue
Is there any command that allows me to list the users with root as secondary group?
I have tried using /etc/group and /etc/passwd files, but i don't know how to difference between primary and secondary groups in there.
Solution
$ for u in $(awk -F: '$4 != 0 {print $1}' /etc/passwd);do groups $u;done | grep root
We take each username from /etc/passwd, excluding users whose primary gid is root (0), then ask ‘groups’ what memberships they have, and finally ‘grep’ just the ones we’re interested in containing root.
Answered By - trcm Answer Checked By - Senaida (WPSolving Volunteer)