Skip to content Skip to main navigation Skip to footer

CentOS /Linux: 创建用户及用户组

对于linux初学者来说,如果想创建一个普通的用户和用户组,该如何来做呢? 如何在 CentOS Linux系统下创建用户并创建用户组呢?本文将会讲述在linux系统下创建用户及用户组的步骤。

CentOS Linux 创建用户及用户组

首先如果你想创建用户或用户组的话,必须先使用具有root权限的用户登录系统, 普通用户是没有权限来创建用户及用户组的。输入下面的命令来创建一个名为testg的用户组:
[cc lang=”php”] $sudo groupadd testg
[/code] 输入下面的命令来创建一个名为testg的用户:
[cc lang=”php”] $sudo useradd testg
[/code] 输出:
[cc lang=”php”] [devops@osetc~]$ sudo useradd testg
useradd: group testg exists – if you want to add this
user to that group, use -g.
[/code] 从上面的命令输出,你可以知道,用户testg并没有创建成功, 因为useradd命令在创建用户的时候,会自动创建一个同名的用户组,那么现在该怎么办呢?可以使用下面的命令将新创建的用户自动加入到已经创建好的testg用户组里:
[cc lang=”php”] $ sudo useradd -g testg testg
[/code] 这样用户和用户组都创建成了,下一步,需要给用户设置密码。输入下面的命令为testg用户设置密码:
[cc lang=”php”] $sudo passwd testg
[/code] 输出:
[cc lang=”php”] [devops@osetc~]$ sudo passwd testg
Changing password for user testg.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
[/code] 当你为testg设置了密码之后,可以使用su testg命令切换到该用户下使用linux系统了。
[cc lang=”php”] [devops@osetc~]$ su testg
[testg@c668f1n02 devops]$ id testg
uid=501(testg) gid=2600(testg) groups=2600(testg)
[/code] done…

0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.