通过 GUI 设置管理员用户 - 命令行等效吗?

Aar*_*ron 7 command-line administrator 12.04

要从 GUI 指定用户为管理员,您只需打开该用户的属性并选择帐户类型作为“管理员”选项。

在此处输入图片说明

如果用户已经存在,选择这个账户类型在系统层面有什么影响? (添加到sudo组,修改到 /etc/passwd 或 /etc/sudoers...等)

我将如何从命令行完成此操作(将用户指定为“管理员”)

War*_*ill 5

对于 12.04 之前的 Ubuntu,假设用户已经存在

sudo  adduser username admin
Run Code Online (Sandbox Code Playgroud)

对于 12.04 及更高版本

sudo  adduser username sudo 
Run Code Online (Sandbox Code Playgroud)

替换username为用户名。

如果你检查 sudoers 文件,sudo cat /etc/sudoers你会看到这个(从 12.04 开始)或类似的


#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
Run Code Online (Sandbox Code Playgroud)

该行%sudo ALL=(ALL:ALL) ALL表示sudo组的成员具有管理权限。此答案开头的命令根据您使用的 Ubuntu 版本将用户添加到sudoadmin组。这里有更多信息:

RootSudo - 社区 Ubuntu 文档