在Linux
中我们可以授予 sudo
访问权限来允许非 root 用户执行管理命令。sudo
命令在不使用 root
用户密码的情况下为用户提供管理访问。
当用户需要执行管理命令时,可以使用 sudo
命令前执行该命令。然后用户就有了 root
用户的权限执行该命令。
请注意以下限制:
/etc/sudoers
配置文件中列出的用户才能使用 sudo
命令。shell
中执行,而不是在 root
shell 中执行。先决条件
root
访问权限流程
以 root 身份,打开 /etc/sudoers
文件。
# visudo
/etc/sudoers
文件定义 sudo
命令应用的策略。
在 /etc/sudoers
文件中,找到为 wheel
管理组中用户授予 sudo
访问权限的行。
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
确保以 %wheel
开头的行前面没有 #
注释符。
保存所有更改并退出编辑器。
将您要授予 sudo
访问权限的用户添加到 wheel
管理组中。
# usermod --append -G wheel <username>
将 *<username*> 替换为用户的名称。
验证步骤
验证该用户是否已被添加到 wheel
管理组中:
# id <username>
uid=5000(<username>) gid=5000(<username>) groups=5000(<username>),10(wheel)