首页 > 其他分享 >错误:/etc/sudoers: syntax error near line

错误:/etc/sudoers: syntax error near line

时间:2022-11-10 18:00:49浏览次数:38  
标签:bin sudoers sudo syntax etc 终端 输入

错误

yang@ubuntu:/etc$ sudo cat sudoers
>>> /etc/sudoers: syntax error near line 26 <<<
sudo: parse error in /etc/sudoers near line 26
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

自此,无法使用sudo命令,无法打开/etc/sudoers文件,当然也无法修改/etc/sudoers文件。

解决办法:

1、打开两个ssh终端,都是用同一个ubuntu用户登录

2、在第一个终端输入以下命令,获取pid

yang@ubuntu:~$ echo $$

3、在第二个终端,输入:

pkttyagent --process 刚刚得到的pid

4、这个时候,第二个终端会卡住,在第一个终端输入:

pkexec visudo

5、然后,第一个终端也卡主,回到第二个终端,会提示输入当前用户密码,输入

6、好吧,输入完密码,第二个终端卡主了,回到第一个终端,会发现,出现了sudoers的内容,编辑出错的地方,保存即可。

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

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

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:
#alex ALL=(ALL) NOPASSWD: ALL
#includedir /etc/sudoers.d

7、完成任务,修改完成,发现就可以继续使用sudo命令了,over

PS:这里用的编辑器是nano,以下是nano简单的保存方式:

linux下在编辑状态下退出请按Ctrl+X,会有两种情形:
①、如果文件未修改,直接退出;
②、如果修改了文件,下面会询问是否需要保存修改。输入Y确认保存,输入N不保存,按Ctrl+C取消返回。如果输入了Y,下一步会提示输入想要保存的文件名。如果不需要修改文件名直接回车就行;若想要保存成别的名字(也就是另存为)则输入新名称然后确定,这个时候也可用Ctrl+C来取消返回。

原文链接:https://blog.csdn.net/qq_43590614/article/details/125819464

 

 

标签:bin,sudoers,sudo,syntax,etc,终端,输入
From: https://www.cnblogs.com/yangzp/p/16877915.html

相关文章

  • LeetCode 763. 划分字母区间
    1、一上来先遍历数组,找到每个字母最后出现的位置。2、再次遍历数组,保持一个last,表示当前至少应该在哪里分割classSolution{public:vector<int>partitionLabel......
  • Leetcode第864题:获取所有钥匙的最短路径(Shortest path to get all keys)
    解题思路想到最短路径问题,自然想到用BFS解决问题,但是只记录位置还不够,还需要记录当前拥有的钥匙状态。需要的数据结构钥匙的个数是\(1-6\),用一个二进制数表示钥匙的状......
  • LeetCode 452. 用最少数量的箭引爆气球
    贪心1、先按照所有起球的右边界排序,记录第一个气球的右边界位置,如果后续气球的左边界小于记录中的值那么这个气球就是可以被箭射中的,这种情况不做处理。2、当出现遍历的......
  • NETCORE 使用中间件获取请求头
    NETCORE使用中间件获取请求头创建项目:框架net6webapi:项目名称:NETCORE.RequestHead   1. 创建中间件 RequestHeaderVerificationMiddleware.csusingMic......
  • [leetcode每日一题]11.10
    864. 获取所有钥匙的最短路径给定一个二维网格 ​​grid​​ ,其中:'.' 代表一个空房间'#' 代表一堵'@'小写字母代表钥匙大写字母代表锁我们从起点开始出发,一次移动是指......
  • leetcode744
    寻找比目标字母大的最小字母Category Difficulty Likes Dislikesalgorithms Easy(45.91%) 249 -TagsCompanies给你一个排序后的字符列表letters,列表中只包含小写英......
  • leetcode69
    x的平方根Category Difficulty Likes Dislikesalgorithms Easy(39.05%) 878 -TagsCompanies给你一个非负整数x,计算并返回x的算术平方根。由于返回类型是整数......
  • leetcode385
    两个数组间的距离值Category Difficulty Likes Dislikesalgorithms Easy(69.82%) 88 -TagsCompanies给你两个整数数组arr1,arr2和一个整数d,请你返回两个数组之......
  • netcore 处理long(雪花Id)精度丢失
    一、扩展修改(Snowflake.Core)    ①、安装依赖包Install-PackageSnowflake.Core     ②、扩展重写  1、扩展雪花Id,通过更改基数生成数字坐落于(6......
  • leetcode852
    山脉数组的峰顶索引Category Difficulty Likes Dislikesalgorithms Easy(71.36%) 313 -TagsCompanies符合下列属性的数组arr称为山脉数组:arr.length>=3存在......