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

错误

1
2
3
4
5
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

1
yang@ubuntu:~$ echo $$

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

1
pkttyagent --process 刚刚得到的pid

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

1
pkexec visudo

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#
# 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

 

 

posted @   西瓜君~  阅读(714)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
历史上的今天:
2021-11-10 K8S的架构及工作原理
2021-11-10 kubernetes中 pause的作用
点击右上角即可分享
微信分享提示