94

I have a user like this:

uid=501(ironsand) gid=500(foo) groups=500(foo),10(wheel),497(git),501(ironsand)

And to change primary group to ironsand like gid=501(ironsand), I typed this command:

sudo usermod -g ironsand ironsand

It changed groups order but didn't change main group like:

uid=501(ironsand) gid=500(foo) groups=501(ironsand),10(wheel),497(git),500(foo)

I thought someone already asked a question like this, but I couldn't find one.

How can I change primary group?

techraf
  • 5,831
  • 10
  • 33
  • 51
ironsand
  • 5,085
  • 12
  • 50
  • 73

1 Answers1

156

Usually you do it like the following.

To assign a primary group to an user:

$ usermod -g primarygroupname username

To assign secondary groups to a user (-a keeps already existing secondary groups intact otherwise they'll be removed):

$ usermod -a -G secondarygroupname username

From man-page:

...
-g (primary group assigned to the users)
-G (Other groups the user belongs to)
-a (Add the user to the supplementary group(s))
...
ndemou
  • 2,659
  • 1
  • 20
  • 27
Adionditsak
  • 3,905
  • 7
  • 21
  • 23