【Linux】 “xxx is not in the sudoers file” 错误解决方法

编程入门 行业动态 更新时间:2024-10-25 06:25:28

【Linux】 “xxx is not in the sudoers file” 错误<a href=https://www.elefans.com/category/jswz/34/1770089.html style=解决方法"/>

【Linux】 “xxx is not in the sudoers file” 错误解决方法

这是由于该用户在"sudoers"文件中不存在,解决方法就是在 etc/sudoers文件里给该用户添加权限

步骤

  1. 切换到etc文件夹下

    cd /etc
    
  2. 切换root用户

    su -
    

    注意:su后面有-,这和su是不同的,在用命令"su"的时候只是切换到root,但没有把root的环境变量传过去,还是当前用户的环境变量,用"su -"命令将环境变量也一起带过去

  3. 由于./etc/sudoers文件默认是只读的,对于root也是,因此需要对sudoers文件添加写权限

    chmod u+w /etc/sudoers
    
  4. 编辑sudoers文件,找到rootALL=(ALL)ALL在它下面添加XXXALL=(ALL)ALL**(XXX是你的用户名)**

    vi /etc/sudoers
    # 添加下面四行中任意一条
    # 允许用户username执行sudo命令(需要输入密码)
    username ALL=(ALL) ALL 
    # 允许用户组username里面的用户执行sudo命令(需要输入密码)
    %username ALL=(ALL) ALL 
    # 允许用户username执行sudo命令并且在执行的时候不输入密码
    username ALL=(ALL) NOPASSWD:ALL 
    # 允许用户组username里面的用户执行sudo命令并目在执行的时候不输入密码
    %username ALL=(ALL) NOPASSWD:ALL 
    
  5. 撤销sudoers文件写权限命令

    chmod u-w /etc/sudoers
    

参考内容
[1]
[2]

更多推荐

【Linux】 “xxx is not in the sudoers file” 错误解决方法

本文发布于:2024-03-08 22:11:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1722595.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:解决方法   错误   xxx   Linux   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!