centos 创建新用户
CentOS is enterprise level Linux distribution which is clone of the RedHat. User management like create, add, remove etc is important part of the daily Administration tasks. In this tutorial we will look how to add new user to the CentOS system.
CentOS是企业级Linux发行版,是RedHat的克隆。 用户管理(例如创建,添加,删除等)是日常管理任务的重要组成部分。 在本教程中,我们将研究如何将新用户添加到CentOS系统。
列出当前用户 (List Current Users)
Before creating new user we will list existing users. We can use different methods to list existing users but following is the most practical way to list existing users. We will cat user names with the cut
command.
在创建新用户之前,我们将列出现有用户。 我们可以使用不同的方法来列出现有用户,但是以下是列出现有用户的最实用方法。 我们将使用cut
命令来管理用户名。
$ cut -f 1 -d : /etc/passwd
使用useradd添加新用户(Add New User with useradd)
Now we can add our new user. We have all ready checked the existing users but if we try to add existing user we will files. We will use useradd
command by providing the user name. In this example the user name will be poftut
.
现在,我们可以添加新用户。 我们已经准备好检查现有用户,但是如果我们尝试添加现有用户,我们将归档。 我们将通过提供用户名来使用useradd
命令。 在此示例中,用户名将为poftut
。
$ useradd poftut
将用户添加到Sudoers (Add User To The Sudoers)
Newly added user will have its own group and will not added to the other groups. Sudoers
is a special mechanism which group name is wheel
. Sudoers can run commands with administrator or root privileges. We can add newly created user to the Sudoers with usermod
command. We will add user poftut
to the wheel
group which is Sudoers group.
新添加的用户将拥有自己的组,并且不会添加到其他组。 Sudoers
是一种特殊的机制,组名是wheel
。 Sudoers可以使用管理员或root特权运行命令。 我们可以使用usermod
命令将新创建的用户添加到Sudoers中。 我们将增加用户poftut
到wheel
组是sudoers文件组。
$ usermod -aG wheel poftut
列出Wheel Group或Sudoers用户 (List Wheel Group or Sudoers Users)
We can list current wheel
group user members with the following command.
我们可以使用以下命令列出当前的wheel
组用户成员。
$ cat /etc/group
将Shell更改为新用户(Change Shell To New User)
We can practically change shell to the newly created user with the su
command. In this example we will change to the user poftut
like below.
实际上,我们可以使用su
命令将shell更改为新创建的用户。 在此示例中,我们将如下所示更改为用户poftut
。
$ su - poftut
centos 创建新用户