xxx is not in the sudoers file. This incident will be reported.

来源:互联网 发布:mac android sdk 路径 编辑:程序博客网 时间:2024/06/06 09:51

xxx is not in the sudoers file. This incident will be reported.

ubuntu下使用sudo命令遇到如下问题:

xxx is not in the sudoers file. This incident will be reported.

解决方案如下:

  1. 使用su -命令切换到root用户(注意有- ,这和su是不同的,在用命令su的时候只是切换到root,但没有把root的环境变量传过去,还是当前用户的环境变量,用su -命令将环境变量也一起带过去,就像和root登录一样),输入root的密码。

  2. 输入visudo -f /etc/sudoers打开sudoers文件,可以看到前面有这样一行注释:

    # This file MUST be edited with the ‘visudo’ command as root.

    这是因为visudo会检查语法错误,而vi或者nano之类的命令不会检查错误。

    将光标移到最下面,查找有没有这样的一行文本#includedir /etc/sudoers.d,如果有的话继续第3步,否则跳到第4步,对于前者,文件开始处一般会有这样的注释,提示你最好不要直接修改/etc/sudoers文件:

    # Please consider adding local content in /etc/sudoers.d/ instead of
    # directly modifying this file.

  3. 对于存在#includedir /etc/sudoers.d的情况,把修改内容添加到新的文件。Ctrl + X退出当前文件,执行cp /etc/sudoers.d/README /etc/sudoers.d/my_sudoers复制一个文件,文件名可以自己定,这里是my_sudoers,使用visudo -f /etc/sudoers.d/my_sudoers打开文件,可以看到文件开始有这样的注释(来自README文件):

    # Note that there must be at least one file in the sudoers.d directory (this
    # one will do), and all files in this directory should be mode 0440.

    我们的配置文件是从README复制过来的,所以满足这里的条件,把以下代码加入文件末尾(其中xxx是你的用户名),Ctrl + XYEnter保存退出即可:

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

  4. 对于不存在#includedir /etc/sudoers.d的情况,找到root ALL=(ALL:ALL) ALL,复制一行放在下面,把前面的root改成你的用户名,Ctrl + XYEnter保存退出即可。

参考文档:

  1. Sudoers - Community Help Wiki
  2. Ubuntu技巧之 is not in the sudoers file解决方法_Linux教程_Linux公社-Linux系统门户网站
  3. Linux用户配置sudo权限(visudo) - 怀揣梦想,努力前行 - 博客频道 - CSDN.NET
  4. linux下的visudo命令 - 曾经有你的森林 - 博客频道 - CSDN.NET
  5. /etc/sudoers - asnjudy - 博客园
0 0
原创粉丝点击