ubuntu16 解决无sudo 权限

在使用ubuntu的过程中修改了/etc/sudoers文件导致出现如下错误:

 

sudo: parse error in /etc/sudoers near line 32
sudo: no valid sudoers sources found, quitting
 
sudo: unable to initialize policy plugin
 
使用vim gedit等均无法打开/etc/sudoers文件

 

解决办法 执行下面命令

pkexec visudo

此时会报错如下 

==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/sbin/visudo' as the super user
Authenticating as: ubuntu,,, (ubuntu)
Password:
polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
==== AUTHENTICATION FAILED ===
Error executing command as another user: Not authorized
This incident has been reported.

无需惊慌 按照我的步骤来

 

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

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

echo $$

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

pkttyagent --process 刚刚得到的pid

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

pkexec visudo

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

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

7、修改文件内容

 

Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
 
 
root ALL=(ALL:ALL) ALL
 
%admin ALL=(ALL) ALL
 
%sudo ALL=(ALL:ALL) NOPASSWD:ALL

7、输入 Ctrl+X ,输入Y ,输入 回车,输入Q 完成保存文件

(6条消息) 错误:/etc/sudoers: syntax error near line_六十英里的博客-CSDN博客

posted @ 2023-02-22 12:18  hanwei666  阅读(302)  评论(0编辑  收藏  举报
……