sag*_*ise 18 command-line sudo users privileges
我已经在 ubuntu 中激活了 root 用户,并且想使用 ubuntu 作为没有 DE 的服务器。为此,我想禁用授予第一个用户的 sudo 权限。如何从命令行执行此操作?我知道我可以使用 GUI 但如何从命令行使用它?
Bri*_*les 14
有问题的用户具有 sudo 权限,因为它在admin组中。正如 wojox 所评论的,您可以使用visudo和删除 admin 组中的 sudo 权限,但这会从admin 组的所有成员中删除 sudo 功能,而不仅仅是一个用户。
或者,您可以从管理员组中删除用户。如果面向屏幕vi被认为是足够的命令行,请运行vigr并从适当的行中删除用户名。
对于“纯”命令行解决方案,请尝试gpasswd,因为它管理 /etc/group 并且可以从组中添加和删除用户。
root@toki:~# id -Gn username
username adm dialout cdrom plugdev lpadmin admin sambashare
# ^- the group to remove
root@toki:~# gpasswd -d username admin
Removing user username from group admin
root@toki:~# id -Gn username
username adm dialout cdrom plugdev lpadmin sambashare
# ^- username not a member
root@toki:~# gpasswd -a username admin
Adding user username to group admin
root@toki:~# id -Gn username
username adm dialout cdrom plugdev lpadmin admin sambashare
Run Code Online (Sandbox Code Playgroud)
在我意识到有一种不那么愚蠢的方法来做到这一点之前,下面是我的第一个答案。
如果您想要更复杂的方法来执行此操作,可以使用usermod.
这是usermod手册页的引用:
-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
A list of supplementary groups which the user is also a member of.
Each group is separated from the next by a comma, with no intervening
whitespace. The groups are subject to the same restrictions as the
group given with the -g option.
If the user is currently a member of a group which is not listed, the
user will be removed from the group. This behaviour can be changed via
the -a option, which appends the user to the current supplementary group
list.
Run Code Online (Sandbox Code Playgroud)
因此,您必须为用户指定除admin.
root@toki:~# id username
uid=1000(username) gid=1000(username) groups=1000(username),4(adm),20(dialout),24(cdrom),46(plugdev),111(lpadmin),119(admin),122(sambashare)
root@toki:~# usermod -G 4,20,24,46,111,122 username
root@toki:~# id username
uid=1000(username) gid=1000(username) groups=1000(username),4(adm),20(dialout),24(cdrom),46(plugdev),111(lpadmin),122(sambashare)
Run Code Online (Sandbox Code Playgroud)
最后,它违反了问题的精神,但可以users-admin从命令行键入以修改用户和组。
| 归档时间: |
|
| 查看次数: |
62241 次 |
| 最近记录: |