Red Hat Training
A Red Hat training course is available for RHEL 8
23.2. 为用户授予 sudo 访问权限
系统管理员可以授予 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)
其他资源
-
sudo (
8)、visudo (8)
和sudoers (5)
手册页