don't use usermod -- use gpasswd [was Re: Groups]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 15, 2004 at 04:15:18PM +0100, Nick Pierpoint wrote:
> > How do I add "john" to the group called "users"
> I believe usermod is the command you're after.
> To put "john" in the "users" group:
>     usermod -g users john

Eep, don't do this. It's an easy mistake to make, because it seems
intuitively like the thing you want to do. However, there's a problem:
you're not adding the user to the group, you're changing his primary group
(the one listed in the /etc/passwd file). This'll remove him from any
existing group there.

So, you might think, okay, I'll use the usermod -G option instead -- that
works for supplementary groups (the ones in /etc/group). But there's a
problem with that too -- it can't actually add to the current list, just
_completely replace_ the groups the user is a member of. So you'd need to
list on the command line each group you want john to still be a part of --
"usermod -G john,users,staff,websrv,whatever". That's usually not what you
want to do.

Luckily, there's a solution -- the oddly-named command "gpasswd" does
exactly the right thing. (It also has some less-used features dealing with
group passwords -- hence the name.) So:

   gpasswd users -a john

and you're all set.

-- 
Matthew Miller           mattdm@xxxxxxxxxx        <http://www.mattdm.org/>
Boston University Linux      ------>                <http://linux.bu.edu/>



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux