This question already has an answer here:

how to verify that new user was added to group?


by this syntax I will add the user dog to group - white_house_group

usermod -a -G white_house_group dog

after that , how to verify that user dog is really in white_house_group group?

marked as duplicate by Jeff Schaller, Wouter Verhelst, andcoz, Kusalananda, telcoM Jan 22 '18 at 17:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


The usermod -a -G command will add the given user to a supplementary group. The change will be reflected for the user the next time that user logs in.

The user will see the new group in the output of the groups command, and in id -nG. Any other user may use id -nG dog.

The username of the user will additionally be listed in the group's entry in /etc/group and/or in the output of getent group (also getent group white_house_group to only see that one group).

As a programmatic example:

usermod -a -G white_house_group dog
if id -nG dog | ! grep -q white_house_group; then
   echo 'user not added to group!' >&2
   exit 1

... but one may argue that usermod should exit with a failure if the modification was unsuccessful:

if ! usermod -a -G ...; then
    echo error >&2
    exit 1

However, I don't have a Linux system to test this on.

  • so just to summary - I need to do id -nG dof | grep white_house_group – jango Jan 22 '18 at 10:56
  • @jango Something like that, yes. I've added another example in the answer. – Kusalananda Jan 22 '18 at 10:59

You can run the command:

id <username>

and so

id dog

Just use below command

groups dog 

It will show for which all the groups user dog belongs to

Not the answer you're looking for? Browse other questions tagged or ask your own question.