Ubuntu:新增和删除用户,修改用户组信息。
参考:https://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-ubuntu-16-04#how-to-delete-a-user。
Linux
上root用户是权力最大的用户,但是也非常危险,处于安全考虑,增加个人用户是必要的方法,下文讲了讲在Ubuntu
上如何新增和删除用户。
创建用户
实例: root
用户新增用户chenming
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17root@iZhp3fz3iqsadyes2s8ay8Z:~# adduser chenming
Adding user `chenming' ...
Adding new group `chenming' (1000) ...
Adding new user `chenming' (1000) with group `chenming' ...
Creating home directory `/home/chenming' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for chenming
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
首先创建了一个新的用户组chenming
。
在这个组内新建了用户chenming
。
要求你输入密码。
要求输入一些其他信息,可以按回车略过。
最后按下y
对以上信息进行确认。
实例:非root
用户新增用户
1 | $sudo adduser chenming |
给用户授权
实例:把chenming
加到sudo
组里面
1 | root@iZhp3fz3iqsadyes2s8ay8Z:~# groups chenming |
可以看到,chenming
只在chenming
的组里面(前面是用户名,冒号后面是组名)。在这个组里面,可能很多命令你都不能执行。
1 | root@iZhp3fz3iqsadyes2s8ay8Z:~# usermod -aG sudo chenming |
再来看一下:
1 | root@iZhp3fz3iqsadyes2s8ay8Z:~# groups chenming |
look,进入了sudo组了,这下你可以臭屁了。
还有一种方法可以加入sodu
组。
如果是root
用户。1
root@iZhp3fz3iqsadyes2s8ay8Z:~# visudo
这个时候会打开一个文本编辑器,去编辑/etc/sudoer
这个文件,可能是vim
,也可能是nano
。
找到:
1 | # User privilege specification |
在下面加入:
1 | chenming ALL=(ALL:ALL) ALL |
保存(vim下是:x
,nano
下是ctrl+x
),退出,这样chenming
这个用户就加入了sudo
组。
删除用户
仅仅删除用户:1
2
3
4root@iZhp3fz3iqsadyes2s8ay8Z:~# deluser chenming
Removing user `chenming' ...
Warning: group `chenming' has no more members.
Done.
将用户的目录也删除:1
root@iZhp3fz3iqsadyes2s8ay8Z:~# deluser --remove-home chenming
但这个时候,这个已经被删除的用户还是在sudo
组里面。
参照上面的过程,使用visudo命令,删掉增加的那一行即可。