Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The command I use is:

sudo useradd -g users tom

It should add tom to the group users, but I can't find tom in users when checking /etc/group.

However, if I just try:

sudo useradd -G users jim

I find that jim is added to users successfully.

Anyone has ever come across this problem?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Note: useradd is a low-level utility and it is highly recommended you use adduser (or usermod) instead on Ubuntu/Debian systems

  • You are better off using the id -Gn username command to check primary/secondary membership rather than relying on /etc/group
  • The -g option to useradd sets the primary (or login) group of a new user

    • If set to an existing group, this will not be reflected in /etc/group
    • But you can see the existing GID in /etc/passwd or using id -Gn username
    • Example (group izx is gid 1000):
      $ sudo useradd -g izx tom
      $ grep ^izx /etc/group
      izx:x:1000:
      $ grep ^tom /etc/passwd
      tom:x:1008:1000::/home/tom:/bin/sh
      $ id -Gn tom
      izx
      
  • The -G option to useradd sets the secondary (or supplementary) group(s) of a new user

    • These memberships will be reflected in /etc/group and using id -Gn username
    • But not in /etc/passwd (compare to -g above)
    • Example (group izx is gid 1000):
      $ sudo useradd -G izx harry
      $ grep ^izx /etc/group
      izx:x:1000:harry
      $ grep ^harry /etc/passwd
      harry:x:1009:1009::/home/harry:/bin/sh
      $ id -Gn harry
      harry izx
      
share|improve this answer
    
Thank you for the answer! –  xczzhh Jul 24 '12 at 17:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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