首页 > linux日常,服务器相关 > redhat解释gpasswd与usermod区别

redhat解释gpasswd与usermod区别

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.

上一篇: gpasswd -a user1 group1和usermod -g group1 user1 的区别

下一篇: nginx提示:500 Internal Server Error错误的解决方法