如何使用gpasswd命令管理组

时间:2020-03-05 15:28:30  来源:igfitidea点击:

GPASSWD命令用于Linux中以删除组的用户,将用户添加到组,列表组成员并为组设置密码。

gpasswd命令在Linux中改变'/etc/group'和'/etc/gshadow'文件。

在本教程中,我们了解如何使用gpasswd命令管理Linux组。

gpasswd命令语法

让我们检查GPasswd命令的语法及其选项。

gpasswd [options] group
-a, --add user Add the user to the named group.
-d, --delete user Remove the user from the named group.
-A, --administrators user,... Set the list of administrative users.
-M, --members user,... Set the list of group members.

使用gpasswd comand将用户添加到组

让我们检查如何将"user1"添加到组"销售"

$gpasswd -a user1 sales

将多个用户添加到组

在下面的命令之后将多个用户添加到Sales组:

$gpasswd -M user1,user2,user3 sales

从组中删除用户

我们可以使用"-d""选项来从组中删除用户。

以下命令将从"销售"组中删除用户的"User2"。

$gpasswd -d user2 sales

将用户设置为组管理员

我们使用-a选项将用户设置为组管理员。

以下示例将"User1"和"User2"设置为"销售"组的组管理。

$gpasswd -A user1,user2 sales

或者

$gpasswd -A user1 linuxgroup

为组设置密码

它非常罕见的我们使用群组密码,但我喜欢向我们展示它有一个选择。

$gpasswd linuxgroup
Changing the password for group linuxgroup
New Password:
Re-enter new password: