Linux中的用户组

I have heard that Linux have groups. I wonder that how can use groups in Linux ? Linux user groups are used to groups users so for privilege and permission issues can be solved for multiple users easily. For example if we have a file and want to read access for 47 Linux users we can use groups mechanism to group these users and give access to the newly created group.

我听说Linux有小组。 我不知道如何在Linux中使用组? Linux用户组用于对用户进行分组,因此可以轻松地为多个用户解决特权和权限问题。 例如,如果我们有一个文件并想要读取47个Linux用户的访问权限,则可以使用组机制对这些用户进行分组,并授予对新创建的组的访问权限。

列出当前用户组 (List Current User Groups)

First thing we will do is listing user groups in a Linux system. We can list current user group like below

我们要做的第一件事是列出Linux系统中的用户组。 我们可以像下面列出当前用户组

$ groups
List Current User Groups
List Current User Groups
列出当前用户组

We can see that current user is joined groups like ismail adm sudo etc.

我们可以看到当前用户已加入ismail adm sudo等组。

列出所有组 (List All Groups)

But if we want to list all groups those exists in Linux system we can use following command.

但是,如果要列出Linux系统中存在的所有组,则可以使用以下命令。

$ sudo cut -d: -f1 /etc/group
List All Groups
List All Groups
列出所有组

创建组(Create Group)

We can create new group to add user. New group creation can be done like below.

我们可以创建新组以添加用户。 可以像下面这样完成新的组创建。

$ sudo groupadd test
  • We have added group named test

    我们添加了名为test的

移除群组(Remove Group)

Removing an existing group can be done with groupdel method.

可以使用groupdel方法删除现有的组。

$ sudo groupdel test
  • Remove group named test

    删除名为test的

组文件(Group File)

Group file is the database used by groups. Actually it is a text file like below.

组文件是组使用的数据库。 实际上,它是一个文本文件,如下所示。

$ cat /etc/group
Group File
Group File
组文件
  • And it is generally resides in /etc/group 

    它通常位于/ etc / group中

  • For the first like root is group name

    第一个like root是组名

  • is the password where it is stored in /etc/gshadow

    x是密码存储在/ etc / gshadow中的密码

  • is the group id

    组ID为0

将用户添加到组 (Add User To the Group)

We can add existing user to the existing group  by using usermod command

我们可以使用usermod命令将现有用户添加到现有组中

$ sudo usermod  -a -G root ismail
  • usermod -a is command to add user to group

    usermod -a是用于将用户添加到组的命令

  • -G root is used to specify group

    -G root用于指定组

  • ismail is the user name

    ismail是用户名

LEARN MORE  Linux Whoami Command Tutorial To Find Current User
了解更多Linux Whoami命令教程以查找当前用户

从组中删除用户(Remove User From Group)

We can remove existing user to the existing group  by using usermod command

我们可以使用usermod命令将现有用户删除到现有组中

$ sudo usermod -G root ismail
  • usermod  is command to remove user from group

    usermod是从组中删除用户的命令

  • -G root is used to specify group

    -G root用于指定组

  • ismail is the user name

    ismail是用户名

翻译自: https://www.poftut.com/user-groups-linux/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值