通过GUI设置管理员用户 – 命令行等效?
要从GUI将用户指定为管理员,您只需打开该用户的属性,然后选择帐户类型作为“管理员”选项。
如果用户已存在,那么在系统级别选择此帐户类型会产生什么影响? (添加到sudo组,修改为/ etc / passwd或/etc/sudoers…etc)
我将如何 从命令行 完成此操作 (将用户指定为“管理员”) ?
假设用户已经存在,对于12.04之前的Ubuntu
sudo adduser username admin
对于12.04及更高版本
sudo adduser username sudo
将username
替换为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
行%sudo ALL=(ALL:ALL) ALL
表示sudo组的成员具有管理权限。 本答案开头的命令会根据您使用的Ubuntu版本将用户添加到sudo或admin组。 这里有更多信息:
RootSudo – 社区Ubuntu文档 。