LFCS id -Gn Practice Question
Which TWO commands can be used to display the group membership of a user? (Choose two.)
⚠ Common exam trap
The trap is picking file-based commands (/etc/passwd, /etc/group) that only show partial membership, instead of the NSS-aware commands (id -Gn, groups) that report complete group membership.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
id -Gn username
Option A, 'id -Gn username', is correct because the -G flag lists all group IDs the user belongs to and -n converts those GIDs to group names, so it prints every group name the user is a member of. Option D, 'groups username', is correct because the groups command prints the group names that the specified user belongs to, directly showing group membership. Option B, 'cat /etc/passwd | grep username', only shows the user's passwd entry, which contains the primary GID but not supplementary group memberships. Option C, 'id -g username', prints only the primary group ID (or name with -n), not the full set of groups. Option E, 'grep username /etc/group', only finds groups where the username appears in the member list and misses the user's primary group, so it does not reliably display complete group membership.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
id -Gn username
Why this is correct
id -Gn username prints only the supplementary group names for that user, one line of space-separated groups, which directly answers the membership query. It reads the same account database entries as id without the numeric UID and GID output.
- ✗
cat /etc/passwd | grep username
Why it's wrong here
/etc/passwd stores each user's primary GID in field four, not supplementary group names, so this shows no full membership. It is tempting because grepping passwd is a common way to inspect account details, but /etc/group holds the supplementary mappings.
- ✗
id -g username
Why it's wrong here
Incorrect. `id -g username` shows only the primary group ID (numeric), not all groups.
- ✓
groups username
Why this is correct
groups reads the user's group database entries and prints all groups the account belongs to, including the primary group, giving a direct membership listing. Passing the username queries that account rather than the invoking user, satisfying the display requirement.
- ✗
grep username /etc/group
Why it's wrong here
/etc/group lists a group's members in its final field, but a user's primary group appears only in /etc/passwd, so this misses it. It is tempting because grepping /etc/group does reveal supplementary memberships, which is why it is often paired with id.
Go deeper
Related to this question
About these practice questions
This LFCS question is part of Courseiva's 406-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Linux Foundation exam blueprint
This LFCS practice question is part of Courseiva's free Linux Foundation certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LFCS exam.