解决方法"/>
【Linux】 “xxx is not in the sudoers file” 错误解决方法
这是由于该用户在"sudoers"文件中不存在,解决方法就是在 etc/sudoers文件里给该用户添加权限
步骤
-
切换到etc文件夹下
cd /etc
-
切换root用户
su -
注意:su后面有-,这和su是不同的,在用命令"su"的时候只是切换到root,但没有把root的环境变量传过去,还是当前用户的环境变量,用"su -"命令将环境变量也一起带过去
-
由于./etc/sudoers文件默认是只读的,对于root也是,因此需要对sudoers文件添加写权限
chmod u+w /etc/sudoers
-
编辑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
-
撤销sudoers文件写权限命令
chmod u-w /etc/sudoers
参考内容
[1]
[2]
更多推荐
【Linux】 “xxx is not in the sudoers file” 错误解决方法
发布评论