准备工具
本篇已Ubuntu Linux系统为例来讲解Linux关于用户和组操作的命令(只有root权限才可以执行下面讲解的命令!)。不用担心其他发行版系统不能使用这些命令,它们的基本操作都是一样的。(本文后面还有英文翻译文章)
创建用户
在终端输入:
useradd -m -g 用户组名 用户名
-m命令的意思为在创建新用户的同时创建这个用户的家目录
-g命令的意思是将新建的用户归属于哪个用户组
以上两个参数可以不加
查看用户
在终端输入:
cat /etc/passwd
如果用户创建成功,在以上命令执行后显示的结果的最后一行就用关于新建用户的信息
为用户设置密码
在终端输入:
passwd 用户名
按照系统提示执行即可为用户设置密码
删除用户
在终端输入:
userdel 用户名
创建用户组
在终端输入:
groupadd 用户组名
随后可以向查看用户信息一样来查看用户组信息,也就是输入命令:
cat /etc/group
如果用户组创建成功,在以上命令执行后显示的结果的最后一行就用关于新建用户组的信息
删除用户组
在终端输入命令:
gourpdel 用户组名
切换用户
输入命令:
su 用户名
还可以输入命令直接切换到用户的家目录,输入命令:
su - 用户名
退出当前用户
输入命令:
exit
The following is the English translation above:
means of preparation
This article uses the Ubuntu Linux system as an example to explain Linux commands about user and group operations (only root permissions can execute the commands explained below!). Don't worry that other distribution systems can't use these commands. Their basic operations are the same.
Create user
Enter at the terminal:
useradd - m - g usergroupname username
-The m command means to create the user's home directory while creating a new user
-The g command means which user group the new user belongs to
The above two parameters can be omitted
View users
Enter at the terminal:
cat /etc/passwd
If the user is created successfully, the last line of the result displayed after the above command is executed will use the information about the new user
Set password for user
Enter at the terminal:
passwd user name
Follow the system prompts to set the password for the user
delete user
Enter at the terminal:
gourpdel user group name
Create user group
Enter at the terminal:
groupadd user group name
Then you can view user group information as you can view user information, that is, enter the command:
cat /etc/group
If the user group is created successfully, the last line of the result displayed after the above command is executed will use the information about the new user group
Delete User Group
Enter the command at the terminal:
gourpdel user group name
Switch users
Enter command:
su user name
You can also enter the command to directly switch to the user's home directory, and enter the command:
su - User name
Exit the current user
Enter command:
exit
标签:group,用户组,Enter,用户,命令,command,user,Linux
From: https://www.cnblogs.com/sokemile/p/17095233.html