用户组及添加用户到组
In Linux users may have different groups registered. By default adding a user to the Linux system will create new user. There are different commands to change user group one of them is useradd
which actually create new user and sets given group to the newly created user. As always we need root privileges to change user group.
在Linux中,用户可能注册了不同的组。 默认情况下,将用户添加到Linux系统将创建新用户。 有不同的命令来更改用户组,其中之一是useradd
,它实际上创建了新用户并将给定组设置为新创建的用户。 与往常一样,我们需要root特权才能更改用户组。
列出用户 (List Users)
Before starting to add user into a group we will list currently existing user accounts. There are a lot of different ways to list user accounts but I like to use following command.
在开始将用户添加到组中之前,我们将列出当前现有的用户帐户。 列出用户帐户的方法有很多,但是我喜欢使用以下命令。
$ cat /etc/passwd | cut -d ':' -f 1
清单群组(List Groups)
We will also list currently existing groups which is stored in a file /etc/group
.
我们还将列出存储在文件/etc/group
中的当前现有/etc/group
。
$ cat /etc/group | cut -d ':' -f 1
更改主要组(Change Primary Group)
Linux users may have more than one group. We call them primary and other groups. We will change user test primary group to mysql. Primary group is used to assign group to the files and directories user created.
Linux用户可能有多个组。 我们称它们为主要群体和其他群体。 我们将用户测试主组更改为mysql。 主组用于将组分配给用户创建的文件和目录。
In this example we will change user test primary group to the test
在此示例中,我们将用户测试主要组更改为测试
$ usermod -g mysql test
usermod command will mdify usergroup
usermod命令将mdify用户组
-g mysql provides group parameter named mysql
-g mysql提供名为mysql的组参数
test is the user the group will be changed.
测试是要更改组的用户。
添加其他组 (Add Other Groups)
We can add user to the other groups. In this example we will add user test to the group root. Group root is not primary group of the test . We will use -G
option in order to specify other group.
我们可以将用户添加到其他组。 在此示例中,我们将用户测试添加到组root中。 组根不是测试的主要组。 我们将使用-G
选项以指定其他组。
$ usermod -G root test
usermod is command that will change other group memebership
usermod是将更改其他组成员身份的命令
-G root provides change for test user other group
-G root为测试用户其他组提供更改
test is username
测试是用户名
添加到多个组(Add To Multiple Groups)
Some times we may need to add single user to the multiple groups in a single command. We can use -G
options with multiple group names like below. the group names are delimited with command. In this example we will add user
testto the groups named
rootand
mysql`
有时我们可能需要在单个命令中将单个用户添加到多个组中。 我们可以将-G
选项与多个组名一起使用,如下所示。 组名用命令定界。 在这个例子中,我们将user
测试添加to the groups named
root and
mysql` to the groups named
$ usermod -G root,mysql test
usermod is command
usermod是命令
-G root,mysql will change test user group memberships
-G root,mysql将更改测试用户组成员身份
如何将用户添加到组? 信息移植 (How To Add A User To A Group? Infografic)
用户组及添加用户到组