解决 Debian 11 下 “用户不在 sudoers 文件中。此事将被报告” 的问题

首先用 root 用户登录终端:

su - root

查看 sudo 配置文件的权限:

ls -l /etc/sudoers

输出:-r--r----- 1 root root 694 6月 4 02:45 /etc/sudoers

输出结果显示,root 用户没有写的权限,临时赋予:

chmod 640 /etc/sudoers

再次查看,写的权限已经添加:

ls -l /etc/sudoers

输出:-rw-r----- 1 root root 694 6月 4 02:45 /etc/sudoers

编辑 sudoers 文件:

vi /etc/sudoers

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

在下面添加一行:user是你的用户名,请自行修改。
# User privilege specification
root ALL=(ALL:ALL) ALL
user ALL=(ALL:ALL) ALL

改为文件的默认权限:

chmod 440 /etc/sudoers

输出:-r--r----- 1 root root 694 6月 4 03:07 /etc/sudoers

退出 root 切换回普通用户:

exit

再次运行 sudo 命令,完美解决!

标签

发表评论